From f1aeb947b75b04c68f3255f728690a3cb082dd6f Mon Sep 17 00:00:00 2001 From: Pritesh Nandgaonkar Date: Mon, 18 Nov 2019 12:37:16 -0800 Subject: [PATCH] Persist the state of the support form Summary: This diff migrates the current state variables of the support form to the redux store, so that they can be persisted. This change will make them exportable and also solve the bug, where user navigates away from the form and comes back to see the support form's data vanished. Right now the videos are not persisted, as its uploading bit is a work in progress. Reviewed By: passy Differential Revision: D18531674 fbshipit-source-id: b1e824377da55cf531312920ff1bb5b862a12010 --- src/reducers/supportForm.tsx | 46 ++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-) diff --git a/src/reducers/supportForm.tsx b/src/reducers/supportForm.tsx index abf2ab14e..37a8fb459 100644 --- a/src/reducers/supportForm.tsx +++ b/src/reducers/supportForm.tsx @@ -8,13 +8,26 @@ */ import {Actions} from './'; +export type SupportFormV2State = { + title: string; + description: string; + commitHash: string; + appName: string; +}; + export type State = { webState: NTUsersFormData | null; + supportFormV2: SupportFormV2State; }; -export type Action = { - type: 'SET_SUPPORT_FORM_STATE'; - payload: NTUsersFormData | null; -}; +export type Action = + | { + type: 'SET_SUPPORT_FORM_STATE'; + payload: NTUsersFormData | null; + } + | { + type: 'SET_SUPPORT_FORM_V2_STATE'; + payload: SupportFormV2State; + }; export type NTUsersFormData = { flipper_trace: string | null; @@ -22,6 +35,21 @@ export type NTUsersFormData = { export const initialState: () => State = () => ({ webState: null, + supportFormV2: { + title: '', + description: [ + '## Context', + 'What are you trying to accomplish at a high level? Feel free to include mocks and tasks.', + '', + '## Problem', + "What's blocking you?", + '', + "## Workarounds I've Tried", + '', + ].join('\n'), + commitHash: '', + appName: '', + }, }); export default function reducer( state: State | undefined, @@ -33,6 +61,11 @@ export default function reducer( ...state, webState: action.payload, }; + } else if (action.type === 'SET_SUPPORT_FORM_V2_STATE') { + return { + ...state, + supportFormV2: action.payload, + }; } else { return state; } @@ -44,3 +77,8 @@ export const setSupportFormState = ( type: 'SET_SUPPORT_FORM_STATE', payload, }); + +export const setSupportFormV2State = (payload: SupportFormV2State): Action => ({ + type: 'SET_SUPPORT_FORM_V2_STATE', + payload, +});