From d4d0027a2bde844a26d3475143afe73210a83029 Mon Sep 17 00:00:00 2001 From: mkzie2 Date: Mon, 12 Aug 2024 18:56:25 +0700 Subject: [PATCH 1/8] fix: request early cancellation form does not save draft --- src/ONYXKEYS.ts | 3 + src/components/FeedbackSurvey.tsx | 82 ++++++++++++++++++---------- src/types/form/FeedbackSurveyForm.ts | 19 +++++++ src/types/form/index.ts | 1 + 4 files changed, 75 insertions(+), 30 deletions(-) create mode 100644 src/types/form/FeedbackSurveyForm.ts diff --git a/src/ONYXKEYS.ts b/src/ONYXKEYS.ts index 7102d6396381..d083d74fffae 100755 --- a/src/ONYXKEYS.ts +++ b/src/ONYXKEYS.ts @@ -571,6 +571,8 @@ const ONYXKEYS = { REIMBURSEMENT_ACCOUNT_FORM_DRAFT: 'reimbursementAccountDraft', PERSONAL_BANK_ACCOUNT_FORM: 'personalBankAccount', PERSONAL_BANK_ACCOUNT_FORM_DRAFT: 'personalBankAccountDraft', + FEEDBACK_SURVEY_FORM: 'feedbackSurveyForm', + FEEDBACK_SURVEY_FORM_DRAFT: 'feedbackSurveyFormDraft', EXIT_SURVEY_REASON_FORM: 'exitSurveyReasonForm', EXIT_SURVEY_REASON_FORM_DRAFT: 'exitSurveyReasonFormDraft', EXIT_SURVEY_RESPONSE_FORM: 'exitSurveyResponseForm', @@ -643,6 +645,7 @@ type OnyxFormValuesMapping = { [ONYXKEYS.FORMS.ROOM_SETTINGS_FORM]: FormTypes.RoomSettingsForm; [ONYXKEYS.FORMS.NEW_TASK_FORM]: FormTypes.NewTaskForm; [ONYXKEYS.FORMS.EDIT_TASK_FORM]: FormTypes.EditTaskForm; + [ONYXKEYS.FORMS.FEEDBACK_SURVEY_FORM]: FormTypes.FeedbackSurveyForm; [ONYXKEYS.FORMS.EXIT_SURVEY_REASON_FORM]: FormTypes.ExitSurveyReasonForm; [ONYXKEYS.FORMS.EXIT_SURVEY_RESPONSE_FORM]: FormTypes.ExitSurveyResponseForm; [ONYXKEYS.FORMS.MONEY_REQUEST_DESCRIPTION_FORM]: FormTypes.MoneyRequestDescriptionForm; diff --git a/src/components/FeedbackSurvey.tsx b/src/components/FeedbackSurvey.tsx index 71b0da06bd5f..df3c11cfd468 100644 --- a/src/components/FeedbackSurvey.tsx +++ b/src/components/FeedbackSurvey.tsx @@ -1,15 +1,21 @@ -import React, {useState} from 'react'; +import React, {useEffect, useState} from 'react'; import type {StyleProp, ViewStyle} from 'react-native'; import {View} from 'react-native'; +import {useOnyx} from 'react-native-onyx'; import useLocalize from '@hooks/useLocalize'; -import useTheme from '@hooks/useTheme'; import useThemeStyles from '@hooks/useThemeStyles'; +import {translateLocal} from '@libs/Localize'; import CONST from '@src/CONST'; import type {FeedbackSurveyOptionID} from '@src/CONST'; -import type {TranslationPaths} from '@src/languages/types'; +import ONYXKEYS from '@src/ONYXKEYS'; +import INPUT_IDS from '@src/types/form/FeedbackSurveyForm'; +import isLoadingOnyxValue from '@src/types/utils/isLoadingOnyxValue'; import FixedFooter from './FixedFooter'; +import FormProvider from './Form/FormProvider'; +import InputWrapper from './Form/InputWrapper'; import FormAlertWithSubmitButton from './FormAlertWithSubmitButton'; -import SingleOptionSelector from './SingleOptionSelector'; +import RadioButtons from './RadioButtons'; +import type {Choice} from './RadioButtons'; import Text from './Text'; import TextInput from './TextInput'; @@ -36,40 +42,44 @@ type FeedbackSurveyProps = { isLoading?: boolean; }; -type Option = { - key: FeedbackSurveyOptionID; - label: TranslationPaths; -}; - -const OPTIONS: Option[] = [ - {key: CONST.FEEDBACK_SURVEY_OPTIONS.TOO_LIMITED.ID, label: CONST.FEEDBACK_SURVEY_OPTIONS.TOO_LIMITED.TRANSLATION_KEY}, - {key: CONST.FEEDBACK_SURVEY_OPTIONS.TOO_EXPENSIVE.ID, label: CONST.FEEDBACK_SURVEY_OPTIONS.TOO_EXPENSIVE.TRANSLATION_KEY}, - {key: CONST.FEEDBACK_SURVEY_OPTIONS.INADEQUATE_SUPPORT.ID, label: CONST.FEEDBACK_SURVEY_OPTIONS.INADEQUATE_SUPPORT.TRANSLATION_KEY}, - {key: CONST.FEEDBACK_SURVEY_OPTIONS.BUSINESS_CLOSING.ID, label: CONST.FEEDBACK_SURVEY_OPTIONS.BUSINESS_CLOSING.TRANSLATION_KEY}, +const OPTIONS: Choice[] = [ + {value: CONST.FEEDBACK_SURVEY_OPTIONS.TOO_LIMITED.ID, label: translateLocal(CONST.FEEDBACK_SURVEY_OPTIONS.TOO_LIMITED.TRANSLATION_KEY)}, + {value: CONST.FEEDBACK_SURVEY_OPTIONS.TOO_EXPENSIVE.ID, label: translateLocal(CONST.FEEDBACK_SURVEY_OPTIONS.TOO_EXPENSIVE.TRANSLATION_KEY)}, + {value: CONST.FEEDBACK_SURVEY_OPTIONS.INADEQUATE_SUPPORT.ID, label: translateLocal(CONST.FEEDBACK_SURVEY_OPTIONS.INADEQUATE_SUPPORT.TRANSLATION_KEY)}, + {value: CONST.FEEDBACK_SURVEY_OPTIONS.BUSINESS_CLOSING.ID, label: translateLocal(CONST.FEEDBACK_SURVEY_OPTIONS.BUSINESS_CLOSING.TRANSLATION_KEY)}, ]; function FeedbackSurvey({title, description, onSubmit, optionRowStyles, footerText, isNoteRequired, isLoading}: FeedbackSurveyProps) { const {translate} = useLocalize(); const styles = useThemeStyles(); - const theme = useTheme(); + const [draft, draftResults] = useOnyx(ONYXKEYS.FORMS.FEEDBACK_SURVEY_FORM_DRAFT); + const isLoadingDraft = isLoadingOnyxValue(draftResults); - const selectCircleStyles: StyleProp = {borderColor: theme.border}; - const [reason, setReason] = useState