Skip to content

Commit 0ca6ba4

Browse files
authored
Merge pull request #479 from topcoder-platform/PROD-1999_make-it-async
PROD-1999 made the redirect async -> Dev
2 parents a0d91f1 + 7cafced commit 0ca6ba4

File tree

6 files changed

+19
-39
lines changed

6 files changed

+19
-39
lines changed

src/actions/autoSave.js

+3-8
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,25 @@ export const autoSaveInitErrored = (error) => ({
88
payload: error,
99
});
1010

11-
export const triggerAutoSave = (isTriggered, isSaveLater) => ({
11+
export const triggerAutoSave = (isTriggered, isForced) => ({
1212
type: ACTIONS.AUTO_SAVE.TRIGGER_AUTO_SAVE,
1313
payload: {
1414
isTriggered,
15-
isSaveLater,
15+
isForced,
1616
},
1717
});
1818

1919
export const triggerCookieClear = () => ({
2020
type: ACTIONS.AUTO_SAVE.TRIGGER_COOKIE_CLEARED,
2121
});
2222

23-
export const resetSaveLater = () => ({
24-
type: ACTIONS.AUTO_SAVE.RESET_IS_SAVE_LATER,
25-
payload: false,
26-
});
27-
2823
export const autoSaveCookieCleared = (isCookieCleared) => ({
2924
type: ACTIONS.AUTO_SAVE.COOKIE_CLEARED,
3025
payload: isCookieCleared,
3126
});
3227

3328
export const sendAutoSavedPatch = (dataToSave, challengeId) => (dispatch) => {
34-
return patchChallenge(dataToSave, challengeId)
29+
patchChallenge(dataToSave, challengeId)
3530
.then((patched) => {
3631
dispatch(getChallenge(patched));
3732
})

src/autoSaveBeforeLogin.js

+4-9
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import CryptoJS from "crypto-js";
33
import _ from "lodash";
44
import moment from "moment";
55
import "moment-timezone";
6-
import { navigate } from "@reach/router";
76
import config from "../config";
87
import {
98
autoSaveCookieCleared,
@@ -23,7 +22,7 @@ export const saveUpdatesMiddleware = ({ dispatch, getState }) => {
2322
let challengeId = loadChallengeId() || challenge?.id;
2423
const dataToSave = { progress, form };
2524
const currentStep = _.get(dataToSave, "progress.currentStep", 1);
26-
if (authUser?.isLoggedIn && (autoSave?.isSaveLater || currentStep >= 3)) {
25+
if (authUser?.isLoggedIn && (autoSave.forced || currentStep >= 3)) {
2726
const triggerSave = () => {
2827
challengeId = loadChallengeId() || challenge?.id;
2928
if (!challengeId) {
@@ -67,21 +66,17 @@ export const saveUpdatesMiddleware = ({ dispatch, getState }) => {
6766
: undefined;
6867
const formString = JSON.stringify(dataToSave);
6968
if (metaData?.value !== formString) {
70-
const promise = dispatch(sendAutoSavedPatch(formString, challengeId));
71-
promise.then(() => {
72-
if (autoSave.isSaveLater) navigate("/self-service");
73-
});
69+
dispatch(sendAutoSavedPatch(formString, challengeId));
7470
}
7571
};
7672

7773
return (next) => (action) => {
7874
const result = next(action);
79-
if ([ACTIONS.AUTO_SAVE.TRIGGER_AUTO_SAVE].includes(result.type)) {
80-
handleAutoSave();
81-
}
8275

8376
if ([ACTIONS.AUTO_SAVE.TRIGGER_COOKIE_CLEARED].includes(result.type)) {
8477
clearCache();
78+
} else if ([ACTIONS.AUTO_SAVE.TRIGGER_AUTO_SAVE].includes(result.type)) {
79+
handleAutoSave();
8580
}
8681
return result;
8782
};

src/constants/index.js

-1
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,6 @@ export const ACTIONS = {
594594
COOKIE_CLEARED: "COOKIE_CLEARED",
595595
TRIGGER_AUTO_SAVE: "TRIGGER_AUTO_SAVE",
596596
INIT_ERRORED: "INIT_ERRORED",
597-
RESET_IS_SAVE_LATER: "RESET_IS_SAVE_LATER",
598597
TRIGGER_COOKIE_CLEARED: "TRIGGER_COOKIE_CLEARED",
599598
},
600599
CHALLENGE: {

src/reducers/autoSave.js

+2-7
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const initialState = {
88
triggered: false,
99
cookieCleared: false,
1010
initErrored: null,
11-
isSaveLater: false,
11+
forced: false,
1212
};
1313

1414
const autoSaveReducer = (state = initialState, action) => {
@@ -17,12 +17,7 @@ const autoSaveReducer = (state = initialState, action) => {
1717
return {
1818
...state,
1919
triggered: action.payload.isTriggered,
20-
isSaveLater: action.payload.isSaveLater,
21-
};
22-
case ACTIONS.AUTO_SAVE.RESET_IS_SAVE_LATER:
23-
return {
24-
...state,
25-
isSaveLater: action.payload,
20+
forced: action.payload.isForced,
2621
};
2722
case ACTIONS.AUTO_SAVE.COOKIE_CLEARED:
2823
return {

src/routes/Products/components/BasicInfo/index.jsx

+9-13
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,7 @@ import {
2020
savePageDetails,
2121
saveWorkType,
2222
} from "../../../../actions/form";
23-
import {
24-
triggerAutoSave,
25-
resetSaveLater,
26-
triggerCookieClear,
27-
} from "../../../../actions/autoSave";
23+
import { triggerAutoSave, triggerCookieClear } from "../../../../actions/autoSave";
2824
import { setProgressItem } from "../../../../actions/progress";
2925
import BackIcon from "../../../../assets/images/icon-back-arrow.svg";
3026
import SaveForLaterIcon from "../../../../assets/images/save-for-later-icon.svg";
@@ -58,6 +54,7 @@ const BasicInfo = ({
5854
toggleSupportModal,
5955
workItemConfig,
6056
isLoggedIn,
57+
triggerCookieClear,
6158
breadcrumb = [],
6259
}) => {
6360
const defaultFormData = {
@@ -153,7 +150,7 @@ const BasicInfo = ({
153150
const onNext = () => {
154151
setProgressItem(isLoggedIn ? 7 : 5);
155152
saveBasicInfo(formData);
156-
dispatch(triggerAutoSave(true));
153+
dispatch(triggerAutoSave(true, true));
157154
navigate(isLoggedIn ? `${baseUrl}/review` : `${baseUrl}/login-prompt`);
158155
};
159156

@@ -181,7 +178,7 @@ const BasicInfo = ({
181178
setFirstMounted(false);
182179

183180
return () => {
184-
dispatch(triggerAutoSave(true));
181+
dispatch(triggerAutoSave(true, false));
185182
};
186183
// eslint-disable-next-line react-hooks/exhaustive-deps
187184
}, [basicInfo, currentStep, dispatch, setProgressItem, firstMounted]);
@@ -217,12 +214,10 @@ const BasicInfo = ({
217214
dispatch(getUserProfile());
218215
}, [dispatch]);
219216

220-
const saveForm = (autoSave, saveLater) => {
217+
const saveForm = (autoSave) => {
221218
saveBasicInfo(formData);
222-
dispatch(triggerAutoSave(autoSave, saveLater));
223-
setTimeout(() => {
224-
dispatch(resetSaveLater());
225-
}, 100);
219+
dispatch(triggerAutoSave(autoSave, true));
220+
if (autoSave) navigate("/self-service");
226221
};
227222

228223
return (
@@ -283,7 +278,7 @@ const BasicInfo = ({
283278
disabled={!isFormValid}
284279
size={BUTTON_SIZE.MEDIUM}
285280
type={BUTTON_TYPE.SECONDARY}
286-
onClick={() => saveForm(true, true)}
281+
onClick={() => saveForm(true)}
287282
>
288283
<SaveForLaterIcon />
289284
<span>SAVE FOR LATER</span>
@@ -316,6 +311,7 @@ const mapDispatchToProps = {
316311
savePageDetails,
317312
toggleSupportModal,
318313
saveWorkType,
314+
triggerCookieClear,
319315
};
320316

321317
export default connect(mapStateToProps, mapDispatchToProps)(BasicInfo);

src/routes/Products/components/BasicInfoForm/index.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ const BasicInfoForm = ({
205205
onChange={(e) =>
206206
handleInputChange(e.target.name, e.target.value, e.target.value)
207207
}
208-
onBlur={() => saveForm(false, false)}
208+
onBlur={() => saveForm(false)}
209209
/>
210210
</FormField>
211211
</div>

0 commit comments

Comments
 (0)