Skip to content

Commit fa6bb49

Browse files
ValentinHSaraVieira
authored andcommitted
Reset isForkingSandbox on error (codesandbox#1859)
* Reset isForkingSandbox on error Close codesandbox#1803. I'm not sure what's the best way to reset some state on error with Cerebral though. Basically, I'd like to be able to always reset this state at the end of the `forkSandbox` sequence (https://github.com/codesandbox/codesandbox-client/blob/master/packages/app/src/app/store/sequences.js#L162) instead of doing this in every single action called by this sequence. * Use path for success/error
1 parent 442ddd4 commit fa6bb49

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

packages/app/src/app/store/actions.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,15 +168,16 @@ export function getGitChanges({ api, state }) {
168168
.then(gitChanges => ({ gitChanges }));
169169
}
170170

171-
export function forkSandbox({ state, props, api }) {
171+
export function forkSandbox({ state, props, api, path }) {
172172
const sandboxId = props.sandboxId || state.get('editor.currentId');
173173
const url = sandboxId.includes('/')
174174
? `/sandboxes/fork/${sandboxId}`
175175
: `/sandboxes/${sandboxId}/fork`;
176176

177177
return api
178178
.post(url, props.body || {})
179-
.then(data => ({ forkedSandbox: data }));
179+
.then(data => path.success({ forkedSandbox: data }))
180+
.catch(error => path.error({ error }));
180181
}
181182

182183
export function moveModuleContent({ props, state }) {

packages/app/src/app/store/sequences.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -166,13 +166,18 @@ export const forkSandbox = sequence('forkSandbox', [
166166
factories.track('Fork Sandbox', {}),
167167
set(state`editor.isForkingSandbox`, true),
168168
actions.forkSandbox,
169-
actions.moveModuleContent,
170-
setSandboxData,
171-
set(state`editor.currentId`, props`sandbox.id`),
172-
factories.addNotification('Forked sandbox!', 'success'),
173-
factories.updateSandboxUrl(props`sandbox`),
174-
ensurePackageJSON,
175-
set(state`editor.isForkingSandbox`, false),
169+
{
170+
success: [
171+
actions.moveModuleContent,
172+
setSandboxData,
173+
set(state`editor.currentId`, props`sandbox.id`),
174+
factories.addNotification('Forked sandbox!', 'success'),
175+
factories.updateSandboxUrl(props`sandbox`),
176+
ensurePackageJSON,
177+
set(state`editor.isForkingSandbox`, false),
178+
],
179+
error: set(state`editor.isForkingSandbox`, false),
180+
},
176181
],
177182
false: [
178183
factories.track('Show Server Fork Sign In Modal', {}),

0 commit comments

Comments
 (0)