-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #52028 from callstack-internal/VickyStash/feature/…
…51908-card-name-on-confirmation-page [Workspace Feeds] Card name field on confirmation page
- Loading branch information
Showing
10 changed files
with
121 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
src/pages/workspace/companyCards/assignCard/CardNameStep.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import React from 'react'; | ||
import {useOnyx} from 'react-native-onyx'; | ||
import FormProvider from '@components/Form/FormProvider'; | ||
import InputWrapper from '@components/Form/InputWrapper'; | ||
import type {FormInputErrors, FormOnyxValues} from '@components/Form/types'; | ||
import HeaderWithBackButton from '@components/HeaderWithBackButton'; | ||
import ScreenWrapper from '@components/ScreenWrapper'; | ||
import Text from '@components/Text'; | ||
import TextInput from '@components/TextInput'; | ||
import useAutoFocusInput from '@hooks/useAutoFocusInput'; | ||
import useLocalize from '@hooks/useLocalize'; | ||
import useThemeStyles from '@hooks/useThemeStyles'; | ||
import * as ErrorUtils from '@libs/ErrorUtils'; | ||
import * as ValidationUtils from '@libs/ValidationUtils'; | ||
import AccessOrNotFoundWrapper from '@pages/workspace/AccessOrNotFoundWrapper'; | ||
import * as CompanyCards from '@userActions/CompanyCards'; | ||
import CONST from '@src/CONST'; | ||
import ONYXKEYS from '@src/ONYXKEYS'; | ||
import INPUT_IDS from '@src/types/form/EditExpensifyCardNameForm'; | ||
|
||
type CardNameStepProps = { | ||
/** Current policy id */ | ||
policyID: string; | ||
}; | ||
|
||
function CardNameStep({policyID}: CardNameStepProps) { | ||
const {translate} = useLocalize(); | ||
const {inputCallbackRef} = useAutoFocusInput(); | ||
const styles = useThemeStyles(); | ||
const [assignCard] = useOnyx(ONYXKEYS.ASSIGN_CARD); | ||
|
||
const data = assignCard?.data; | ||
|
||
const submit = (values: FormOnyxValues<typeof ONYXKEYS.FORMS.EDIT_WORKSPACE_COMPANY_CARD_NAME_FORM>) => { | ||
CompanyCards.setAssignCardStepAndData({ | ||
currentStep: CONST.COMPANY_CARD.STEP.CONFIRMATION, | ||
data: { | ||
cardName: values.name, | ||
}, | ||
isEditing: false, | ||
}); | ||
}; | ||
|
||
const validate = (values: FormOnyxValues<typeof ONYXKEYS.FORMS.EDIT_WORKSPACE_COMPANY_CARD_NAME_FORM>): FormInputErrors<typeof ONYXKEYS.FORMS.EDIT_WORKSPACE_COMPANY_CARD_NAME_FORM> => { | ||
const errors = ValidationUtils.getFieldRequiredErrors(values, [INPUT_IDS.NAME]); | ||
const length = values.name.length; | ||
|
||
if (length > CONST.STANDARD_LENGTH_LIMIT) { | ||
ErrorUtils.addErrorMessage(errors, INPUT_IDS.NAME, translate('common.error.characterLimitExceedCounter', {length, limit: CONST.STANDARD_LENGTH_LIMIT})); | ||
} | ||
|
||
return errors; | ||
}; | ||
|
||
return ( | ||
<AccessOrNotFoundWrapper | ||
policyID={policyID} | ||
featureName={CONST.POLICY.MORE_FEATURES.ARE_COMPANY_CARDS_ENABLED} | ||
> | ||
<ScreenWrapper | ||
testID={CardNameStep.displayName} | ||
shouldEnablePickerAvoiding={false} | ||
includeSafeAreaPaddingBottom={false} | ||
> | ||
<HeaderWithBackButton | ||
title={translate('workspace.moreFeatures.companyCards.cardName')} | ||
onBackButtonPress={() => CompanyCards.setAssignCardStepAndData({currentStep: CONST.COMPANY_CARD.STEP.CONFIRMATION, isEditing: false})} | ||
/> | ||
<Text style={[styles.mh5, styles.mt3, styles.mb5]}>{translate('workspace.moreFeatures.companyCards.giveItNameInstruction')}</Text> | ||
<FormProvider | ||
formID={ONYXKEYS.FORMS.EDIT_WORKSPACE_COMPANY_CARD_NAME_FORM} | ||
submitButtonText={translate('common.confirm')} | ||
onSubmit={submit} | ||
style={[styles.flex1, styles.mh5]} | ||
enabledWhenOffline | ||
validate={validate} | ||
> | ||
<InputWrapper | ||
InputComponent={TextInput} | ||
inputID={INPUT_IDS.NAME} | ||
label={translate('workspace.moreFeatures.companyCards.cardName')} | ||
aria-label={translate('workspace.moreFeatures.companyCards.cardName')} | ||
role={CONST.ROLE.PRESENTATION} | ||
defaultValue={data?.cardName} | ||
ref={inputCallbackRef} | ||
/> | ||
</FormProvider> | ||
</ScreenWrapper> | ||
</AccessOrNotFoundWrapper> | ||
); | ||
} | ||
|
||
CardNameStep.displayName = 'CardNameStep'; | ||
|
||
export default CardNameStep; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters