-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Policy category - Add Payroll Code #43151
Changes from all commits
fda657c
bdf8070
b29331a
78cb661
4ad00ea
2cec124
bf7b779
6d1e603
4e6c965
2e60d83
f20f10c
bf3dd2f
ed69bd0
d150bdc
05be40c
9a15098
47d4566
b8aa3b2
ff2c261
1529597
e5c6ca0
2a4637b
3e7bb90
fb3c493
cc0423b
d7f3aa4
3bb29bc
d75e74a
2bc06c9
89fec2f
d884e04
39f60d5
e2ac2e0
1fc92a8
d62c5bd
57a31f3
7d8abfb
529061a
22df8b4
6a340ff
06265b2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
type UpdatePolicyCategoryPayrollCodeParams = { | ||
policyID: string; | ||
categoryName: string; | ||
payrollCode: string; | ||
}; | ||
|
||
export default UpdatePolicyCategoryPayrollCodeParams; |
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,87 @@ | ||||||||||||||
import type {StackScreenProps} from '@react-navigation/stack'; | ||||||||||||||
import React, {useCallback} from 'react'; | ||||||||||||||
import {useOnyx} from 'react-native-onyx'; | ||||||||||||||
import FormProvider from '@components/Form/FormProvider'; | ||||||||||||||
import InputWrapper from '@components/Form/InputWrapper'; | ||||||||||||||
import type {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 Navigation from '@libs/Navigation/Navigation'; | ||||||||||||||
import type {SettingsNavigatorParamList} from '@navigation/types'; | ||||||||||||||
import AccessOrNotFoundWrapper from '@pages/workspace/AccessOrNotFoundWrapper'; | ||||||||||||||
import * as Category from '@userActions/Policy/Category'; | ||||||||||||||
import CONST from '@src/CONST'; | ||||||||||||||
import ONYXKEYS from '@src/ONYXKEYS'; | ||||||||||||||
import ROUTES from '@src/ROUTES'; | ||||||||||||||
import type SCREENS from '@src/SCREENS'; | ||||||||||||||
import INPUT_IDS from '@src/types/form/WorkspaceCategoryForm'; | ||||||||||||||
|
||||||||||||||
type EditCategoryPageProps = StackScreenProps<SettingsNavigatorParamList, typeof SCREENS.WORKSPACE.CATEGORY_PAYROLL_CODE>; | ||||||||||||||
|
||||||||||||||
function CategoryPayrollCodePage({route}: EditCategoryPageProps) { | ||||||||||||||
const styles = useThemeStyles(); | ||||||||||||||
const {translate} = useLocalize(); | ||||||||||||||
const policyId = route.params.policyID ?? '-1'; | ||||||||||||||
const [policyCategories] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${policyId}`); | ||||||||||||||
|
||||||||||||||
const categoryName = route.params.categoryName; | ||||||||||||||
const payrollCode = policyCategories?.[categoryName]?.['Payroll Code']; | ||||||||||||||
const {inputCallbackRef} = useAutoFocusInput(); | ||||||||||||||
|
||||||||||||||
const editPayrollCode = useCallback( | ||||||||||||||
(values: FormOnyxValues<typeof ONYXKEYS.FORMS.WORKSPACE_CATEGORY_FORM>) => { | ||||||||||||||
const newPayrollCode = values.payrollCode.trim(); | ||||||||||||||
if (newPayrollCode !== payrollCode) { | ||||||||||||||
Category.setPolicyCategoryPayrollCode(route.params.policyID, categoryName, newPayrollCode); | ||||||||||||||
} | ||||||||||||||
Navigation.goBack(ROUTES.WORKSPACE_CATEGORY_SETTINGS.getRoute(route.params.policyID, route.params.categoryName)); | ||||||||||||||
}, | ||||||||||||||
[categoryName, payrollCode, route.params.categoryName, route.params.policyID], | ||||||||||||||
); | ||||||||||||||
|
||||||||||||||
return ( | ||||||||||||||
<AccessOrNotFoundWrapper | ||||||||||||||
accessVariants={[CONST.POLICY.ACCESS_VARIANTS.ADMIN, CONST.POLICY.ACCESS_VARIANTS.CONTROL]} | ||||||||||||||
policyID={route.params.policyID} | ||||||||||||||
featureName={CONST.POLICY.MORE_FEATURES.ARE_CATEGORIES_ENABLED} | ||||||||||||||
> | ||||||||||||||
<ScreenWrapper | ||||||||||||||
includeSafeAreaPaddingBottom={false} | ||||||||||||||
style={[styles.defaultModalContainer]} | ||||||||||||||
testID={CategoryPayrollCodePage.displayName} | ||||||||||||||
shouldEnableMaxHeight | ||||||||||||||
> | ||||||||||||||
<HeaderWithBackButton | ||||||||||||||
title={translate('workspace.categories.payrollCode')} | ||||||||||||||
onBackButtonPress={() => Navigation.goBack(ROUTES.WORKSPACE_CATEGORY_SETTINGS.getRoute(route.params.policyID, route.params.categoryName))} | ||||||||||||||
/> | ||||||||||||||
<FormProvider | ||||||||||||||
formID={ONYXKEYS.FORMS.WORKSPACE_CATEGORY_FORM} | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we use a different form name? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i don't see a reason why we should There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not a blocker but in my opinion, each form should have a uniq id, this id App/src/types/form/WorkspaceCategoryForm.ts Lines 10 to 15 in aae4922
|
||||||||||||||
onSubmit={editPayrollCode} | ||||||||||||||
submitButtonText={translate('common.save')} | ||||||||||||||
style={[styles.mh5, styles.flex1]} | ||||||||||||||
enabledWhenOffline | ||||||||||||||
> | ||||||||||||||
<InputWrapper | ||||||||||||||
ref={inputCallbackRef} | ||||||||||||||
InputComponent={TextInput} | ||||||||||||||
defaultValue={payrollCode} | ||||||||||||||
label={translate('workspace.categories.payrollCode')} | ||||||||||||||
accessibilityLabel={translate('workspace.categories.payrollCode')} | ||||||||||||||
inputID={INPUT_IDS.PAYROLL_CODE} | ||||||||||||||
role={CONST.ROLE.PRESENTATION} | ||||||||||||||
maxLength={CONST.MAX_LENGTH_256} | ||||||||||||||
/> | ||||||||||||||
</FormProvider> | ||||||||||||||
</ScreenWrapper> | ||||||||||||||
</AccessOrNotFoundWrapper> | ||||||||||||||
); | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
CategoryPayrollCodePage.displayName = 'CategoryPayrollCodePage'; | ||||||||||||||
|
||||||||||||||
export default CategoryPayrollCodePage; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we need to reset pendingFields as well.