Skip to content

Commit

Permalink
feat: success and error handling (#358)
Browse files Browse the repository at this point in the history
  • Loading branch information
mortennordseth authored Sep 26, 2024
1 parent 96e0630 commit 5ab1925
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/page-modules/contact/means-of-transport/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ export const MeansOfTransportContent = () => {
title={t(PageText.Contact.submit)}
mode={'interactive_0--bordered'}
buttonProps={{ type: 'submit' }}
state={state.matches('submitting') ? 'loading' : undefined}
/>
)}
{state.hasTag('success') && <div>success!</div>}
</form>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ export const meansOfTransportFormMachine = setup({
}
return context;
}),
navigateToErrorPage: () => {
window.location.href = '/contact/error';
},
navigateToSuccessPage: () => {
window.location.href = '/contact/success';
},
},
actors: {
submit: fromPromise(
Expand Down Expand Up @@ -229,12 +235,17 @@ export const meansOfTransportFormMachine = setup({
},

onError: {
target: 'editing',
target: 'error',
},
},
},

success: {
entry: 'navigateToSuccessPage',
type: 'final',
},
error: {
entry: 'navigateToErrorPage',
type: 'final',
},
},
Expand Down
2 changes: 1 addition & 1 deletion src/page-modules/contact/ticket-control/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ const TicketControlPageContent = () => {
title={t(PageText.Contact.submit)}
mode={'interactive_0--bordered'}
buttonProps={{ type: 'submit' }}
state={state.matches('submitting') ? 'loading' : undefined}
/>
)}
{state.matches('success') && <div>success!</div>}
</form>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,12 @@ export const ticketControlFormMachine = setup({
cleanErrorMessages: assign({
errorMessages: () => ({}),
}),

navigateToErrorPage: () => {
window.location.href = '/contact/error';
},
navigateToSuccessPage: () => {
window.location.href = '/contact/success';
},
onInputChange: assign(({ context, event }) => {
if (event.type === 'ON_INPUT_CHANGE') {
const { inputName, value } = event;
Expand Down Expand Up @@ -356,12 +361,17 @@ export const ticketControlFormMachine = setup({
},

onError: {
target: 'editing',
target: 'error',
},
},
},

success: {
entry: 'navigateToSuccessPage',
type: 'final',
},
error: {
entry: 'navigateToErrorPage',
type: 'final',
},
},
Expand Down
1 change: 1 addition & 0 deletions src/page-modules/contact/travel-guarantee/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,7 @@ export const RefundForm = () => {
title={t(PageText.Contact.submit)}
mode={'interactive_0--bordered'}
buttonProps={{ type: 'submit' }}
state={state.matches('submitting') ? 'loading' : undefined}
/>
</div>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,16 @@ export const fetchMachine = setup({
},
}),

navigateToErrorPage: () => {
window.location.href = '/contact/error';
},
navigateToSuccessPage: () => {
window.location.href = '/contact/success';
},

onInputChange: assign(({ context, event }) => {
if (event.type === 'ON_INPUT_CHANGE') {
const { inputName, value } = event;
let { inputName, value } = event;
context.errorMessages[inputName] = [];
return {
...context,
Expand Down Expand Up @@ -246,12 +253,17 @@ export const fetchMachine = setup({
},

onError: {
target: 'editing',
target: 'error',
},
},
},

success: {
entry: 'navigateToSuccessPage',
type: 'final',
},
error: {
entry: 'navigateToErrorPage',
type: 'final',
},
},
Expand Down

0 comments on commit 5ab1925

Please sign in to comment.