-
Notifications
You must be signed in to change notification settings - Fork 3k
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 #45473 from VickyStash/feature/44327-edit-card-name
[No QA] Create new Edit Card Name page
- Loading branch information
Showing
11 changed files
with
132 additions
and
2 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
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
94 changes: 94 additions & 0 deletions
94
src/pages/workspace/expensifyCard/WorkspaceEditCardNamePage.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,94 @@ | ||
import type {StackScreenProps} from '@react-navigation/stack'; | ||
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 TextInput from '@components/TextInput'; | ||
import useAutoFocusInput from '@hooks/useAutoFocusInput'; | ||
import useLocalize from '@hooks/useLocalize'; | ||
import useThemeStyles from '@hooks/useThemeStyles'; | ||
import * as ValidationUtils from '@libs/ValidationUtils'; | ||
import Navigation from '@navigation/Navigation'; | ||
import type {SettingsNavigatorParamList} from '@navigation/types'; | ||
import AccessOrNotFoundWrapper from '@pages/workspace/AccessOrNotFoundWrapper'; | ||
import CONST from '@src/CONST'; | ||
import ONYXKEYS from '@src/ONYXKEYS'; | ||
import type SCREENS from '@src/SCREENS'; | ||
import INPUT_IDS from '@src/types/form/EditExpensifyCardNameForm'; | ||
|
||
// TODO: remove when Onyx data is available | ||
const mockedCard = { | ||
accountID: 885646, | ||
availableSpend: 1000, | ||
nameValuePairs: { | ||
cardTitle: 'Test 1', | ||
isVirtual: true, | ||
limit: 2000, | ||
limitType: CONST.EXPENSIFY_CARD.LIMIT_TYPES.SMART, | ||
}, | ||
lastFourPAN: '1234', | ||
}; | ||
|
||
type WorkspaceEditCardNamePageProps = StackScreenProps<SettingsNavigatorParamList, typeof SCREENS.WORKSPACE.EXPENSIFY_CARD_NAME>; | ||
|
||
function WorkspaceEditCardNamePage({route}: WorkspaceEditCardNamePageProps) { | ||
const {policyID, cardID} = route.params; | ||
|
||
const {translate} = useLocalize(); | ||
const {inputCallbackRef} = useAutoFocusInput(); | ||
const styles = useThemeStyles(); | ||
|
||
const [cardsList] = useOnyx(`${ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST}${policyID}_${CONST.EXPENSIFY_CARD.BANK}`); | ||
const card = cardsList?.[cardID] ?? mockedCard; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
const submit = (values: FormOnyxValues<typeof ONYXKEYS.FORMS.EDIT_EXPENSIFY_CARD_NAME_FORM>) => { | ||
// TODO: add API call when it's supported https://github.com/Expensify/Expensify/issues/407832 | ||
Navigation.goBack(); | ||
}; | ||
|
||
const validate = (values: FormOnyxValues<typeof ONYXKEYS.FORMS.EDIT_EXPENSIFY_CARD_NAME_FORM>): FormInputErrors<typeof ONYXKEYS.FORMS.EDIT_EXPENSIFY_CARD_NAME_FORM> => | ||
ValidationUtils.getFieldRequiredErrors(values, [INPUT_IDS.NAME]); | ||
|
||
return ( | ||
<AccessOrNotFoundWrapper | ||
accessVariants={[CONST.POLICY.ACCESS_VARIANTS.ADMIN, CONST.POLICY.ACCESS_VARIANTS.PAID]} | ||
policyID={policyID} | ||
featureName={CONST.POLICY.MORE_FEATURES.ARE_EXPENSIFY_CARDS_ENABLED} | ||
> | ||
<ScreenWrapper | ||
testID={WorkspaceEditCardNamePage.displayName} | ||
shouldEnablePickerAvoiding={false} | ||
shouldEnableMaxHeight | ||
> | ||
<HeaderWithBackButton title={translate('workspace.card.issueNewCard.cardName')} /> | ||
<FormProvider | ||
formID={ONYXKEYS.FORMS.EDIT_EXPENSIFY_CARD_NAME_FORM} | ||
submitButtonText={translate('common.save')} | ||
onSubmit={submit} | ||
style={[styles.flex1, styles.mh5]} | ||
enabledWhenOffline | ||
validate={validate} | ||
> | ||
<InputWrapper | ||
InputComponent={TextInput} | ||
inputID={INPUT_IDS.NAME} | ||
label={translate('workspace.card.issueNewCard.cardName')} | ||
hint={translate('workspace.card.issueNewCard.giveItNameInstruction')} | ||
aria-label={translate('workspace.card.issueNewCard.cardName')} | ||
role={CONST.ROLE.PRESENTATION} | ||
defaultValue={card?.nameValuePairs?.cardTitle} | ||
ref={inputCallbackRef} | ||
/> | ||
</FormProvider> | ||
</ScreenWrapper> | ||
</AccessOrNotFoundWrapper> | ||
); | ||
} | ||
|
||
WorkspaceEditCardNamePage.displayName = 'WorkspaceEditCardNamePage'; | ||
|
||
export default WorkspaceEditCardNamePage; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import type {ValueOf} from 'type-fest'; | ||
import type Form from './Form'; | ||
|
||
const INPUT_IDS = { | ||
NAME: 'name', | ||
} as const; | ||
|
||
type InputID = ValueOf<typeof INPUT_IDS>; | ||
|
||
type EditExpensifyCardNameForm = Form<InputID, {[INPUT_IDS.NAME]: string}>; | ||
|
||
export type {EditExpensifyCardNameForm}; | ||
export default INPUT_IDS; |
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