Skip to content

Commit 602255d

Browse files
authored
Merge pull request Expensify#67118 from allgandalf/refactorExitSurvey
Refactor src/libs/actions/ExitSurvey.ts to remove Onyx.connect() references
2 parents 7d5a59f + d927472 commit 602255d

3 files changed

Lines changed: 8 additions & 14 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
"test:debug": "TZ=utc NODE_OPTIONS='--inspect-brk --experimental-vm-modules' jest --runInBand",
4747
"perf-test": "NODE_OPTIONS=--experimental-vm-modules npx reassure",
4848
"typecheck": "NODE_OPTIONS=--max_old_space_size=8192 tsc",
49-
"lint": "NODE_OPTIONS=--max_old_space_size=8192 eslint . --max-warnings=332 --cache --cache-location=node_modules/.cache/eslint",
49+
"lint": "NODE_OPTIONS=--max_old_space_size=8192 eslint . --max-warnings=330 --cache --cache-location=node_modules/.cache/eslint",
5050
"lint-changed": "NODE_OPTIONS=--max_old_space_size=8192 ./scripts/lintChanged.sh",
5151
"lint-watch": "npx eslint-watch --watch --changed",
5252
"shellcheck": "./scripts/shellCheck.sh",

src/libs/actions/ExitSurvey.ts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,6 @@ import REASON_INPUT_IDS from '@src/types/form/ExitSurveyReasonForm';
77
import type {ExitReason} from '@src/types/form/ExitSurveyReasonForm';
88
import RESPONSE_INPUT_IDS from '@src/types/form/ExitSurveyResponseForm';
99

10-
let exitReason: ExitReason | undefined;
11-
let exitSurveyResponse: string | undefined;
12-
Onyx.connect({
13-
key: ONYXKEYS.FORMS.EXIT_SURVEY_REASON_FORM,
14-
callback: (value) => (exitReason = value?.[REASON_INPUT_IDS.REASON]),
15-
});
16-
Onyx.connect({
17-
key: ONYXKEYS.FORMS.EXIT_SURVEY_RESPONSE_FORM,
18-
callback: (value) => (exitSurveyResponse = value?.[RESPONSE_INPUT_IDS.RESPONSE]),
19-
});
20-
2110
function saveExitReason(reason: ExitReason) {
2211
Onyx.set(ONYXKEYS.FORMS.EXIT_SURVEY_REASON_FORM, {[REASON_INPUT_IDS.REASON]: reason});
2312
}
@@ -29,7 +18,7 @@ function saveResponse(response: string) {
2918
/**
3019
* Save the user's response to the mandatory exit survey in the back-end.
3120
*/
32-
function switchToOldDot() {
21+
function switchToOldDot(exitReason: ExitReason | undefined, exitSurveyResponse: string | undefined) {
3322
const optimisticData: OnyxUpdate[] = [
3423
{
3524
onyxMethod: Onyx.METHOD.SET,

src/pages/settings/ExitSurvey/ExitSurveyConfirmPage.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import ROUTES from '@src/ROUTES';
2424
import type SCREENS from '@src/SCREENS';
2525
import type {ExitSurveyReasonForm} from '@src/types/form/ExitSurveyReasonForm';
2626
import EXIT_SURVEY_REASON_INPUT_IDS from '@src/types/form/ExitSurveyReasonForm';
27+
import RESPONSE_INPUT_IDS from '@src/types/form/ExitSurveyResponseForm';
2728
import {isEmptyObject} from '@src/types/utils/EmptyObject';
2829
import ExitSurveyOffline from './ExitSurveyOffline';
2930

@@ -38,6 +39,10 @@ function ExitSurveyConfirmPage({route, navigation}: ExitSurveyConfirmPageProps)
3839
selector: (value: OnyxEntry<ExitSurveyReasonForm>) => value?.[EXIT_SURVEY_REASON_INPUT_IDS.REASON] ?? null,
3940
canBeMissing: true,
4041
});
42+
const [exitSurveyResponse] = useOnyx(ONYXKEYS.FORMS.EXIT_SURVEY_RESPONSE_FORM, {
43+
selector: (value) => value?.[RESPONSE_INPUT_IDS.RESPONSE],
44+
canBeMissing: true,
45+
});
4146
const shouldShowQuickTips =
4247
isEmptyObject(tryNewDot) || tryNewDot?.classicRedirect?.dismissed === true || (!isEmptyObject(tryNewDot) && tryNewDot?.classicRedirect?.dismissed === undefined);
4348

@@ -90,7 +95,7 @@ function ExitSurveyConfirmPage({route, navigation}: ExitSurveyConfirmPageProps)
9095
text={translate(shouldShowQuickTips ? 'exitSurvey.takeMeToExpensifyClassic' : 'exitSurvey.goToExpensifyClassic')}
9196
pressOnEnter
9297
onPress={() => {
93-
switchToOldDot();
98+
switchToOldDot(exitReason, exitSurveyResponse);
9499
Navigation.dismissModal();
95100
openOldDotLink(CONST.OLDDOT_URLS.INBOX, true);
96101
}}

0 commit comments

Comments
 (0)