Skip to content

Commit

Permalink
address lint error
Browse files Browse the repository at this point in the history
  • Loading branch information
cretadn22 committed Aug 27, 2024
1 parent 821b234 commit ad21147
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/pages/workspace/reportFields/ReportFieldsInitialValuePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,14 @@ function ReportFieldsInitialValuePage({
const hasAccountingConnections = PolicyUtils.hasAccountingConnections(policy);
const reportField = policy?.fieldList?.[ReportUtils.getReportFieldKey(reportFieldID)] ?? null;
const availableListValuesLength = (reportField?.disabledOptions ?? []).filter((disabledListValue) => !disabledListValue).length;

const [initialValue, setInitialValue] = useState(WorkspaceReportFieldUtils.getReportFieldInitialValue(reportField));

if (!reportField || hasAccountingConnections) {
return <NotFoundPage />;
}
const isTextFieldType = reportField.type === CONST.REPORT_FIELD_TYPES.TEXT;
const isListFieldType = reportField.type === CONST.REPORT_FIELD_TYPES.LIST;
const currentInitialValue = WorkspaceReportFieldUtils.getReportFieldInitialValue(reportField);
const [initialValue, setInitialValue] = useState(currentInitialValue);
const isTextFieldType = reportField?.type === CONST.REPORT_FIELD_TYPES.TEXT;
const isListFieldType = reportField?.type === CONST.REPORT_FIELD_TYPES.LIST;

const submit = useCallback(
(value: string) => {
if (WorkspaceReportFieldUtils.getReportFieldInitialValue(reportField) === value) {
if (currentInitialValue === value) {
if (isListFieldType) {
ReportField.updateReportFieldInitialValue(policyID, reportFieldID, '');
}
Expand All @@ -63,14 +59,14 @@ function ReportFieldsInitialValuePage({
}
Navigation.goBack();
},
[policyID, reportFieldID, initialValue],
[policyID, reportFieldID, isListFieldType, currentInitialValue],
);

const submitForm = useCallback(
(values: FormOnyxValues<typeof ONYXKEYS.FORMS.WORKSPACE_REPORT_FIELDS_FORM>) => {
submit(values.initialValue);
},
[policyID, reportFieldID, initialValue],
[submit],
);

const validateForm = useCallback(
Expand Down Expand Up @@ -100,6 +96,10 @@ function ReportFieldsInitialValuePage({
[availableListValuesLength, policy?.fieldList, translate],
);

if (!reportField || hasAccountingConnections) {
return <NotFoundPage />;
}

return (
<AccessOrNotFoundWrapper
accessVariants={[CONST.POLICY.ACCESS_VARIANTS.ADMIN, CONST.POLICY.ACCESS_VARIANTS.PAID]}
Expand Down

0 comments on commit ad21147

Please sign in to comment.