From e72734615c43276c9468e64d68586b1e710fb1a9 Mon Sep 17 00:00:00 2001 From: Nathaniel Cook Date: Mon, 15 Jan 2024 09:18:21 -0800 Subject: [PATCH] convert WizardRouter from Apollo to urql (#3585) --- web/src/app/wizard/WizardRouter.js | 116 ++++++++++++++--------------- 1 file changed, 55 insertions(+), 61 deletions(-) diff --git a/web/src/app/wizard/WizardRouter.js b/web/src/app/wizard/WizardRouter.js index f8f1ba20cf..9b58c5491c 100644 --- a/web/src/app/wizard/WizardRouter.js +++ b/web/src/app/wizard/WizardRouter.js @@ -12,8 +12,7 @@ import { DateTime } from 'luxon' import { fieldErrors, nonFieldErrors } from '../util/errutil' import WizardForm from './WizardForm' import LoadingButton from '../loading/components/LoadingButton' -import { Mutation } from '@apollo/client/react/components' -import { gql } from '@apollo/client' +import { gql, useMutation } from 'urql' import { Form } from '../forms' import { getService, @@ -84,6 +83,7 @@ export default function WizardRouter() { }, }, }) + const [{ data, fetching, error }, commit] = useMutation(mutation) /* * Get steps for the EP @@ -139,13 +139,10 @@ export default function WizardRouter() { } if (variables) { - commit({ variables }) - .then(() => { - setComplete(true) - }) - .catch((err) => { - const generalErrors = nonFieldErrors(err) - const graphqlErrors = fieldErrors(err).map((error) => { + commit(variables).then((result) => { + if (result.error) { + const generalErrors = nonFieldErrors(result.error) + const graphqlErrors = fieldErrors(result.error).map((error) => { const name = error.field .split('.') .pop() // get last occurrence @@ -160,7 +157,10 @@ export default function WizardRouter() { if (errors.length) { setErrorMessage(errors.map((e) => e.message || e).join('\n')) } - }) + } else { + setComplete(true) + } + }) } } @@ -191,57 +191,51 @@ export default function WizardRouter() { } } - return ( - - {(commit, { data, error, loading }) => { - if (redirect && data && data.createService) { - return - } + if (redirect && data && data.createService) { + return + } - return ( - - -
submit(e, isValid, commit)} - disabled={loading} - > - - setValue(value)} - /> - - - - -
-
- onDialogClose(data)} - > - - {renderSubmittedContent()} - - - - -
- ) - }} -
+ return ( + + +
submit(e, isValid, commit)} + disabled={fetching} + > + + setValue(value)} + /> + + + + +
+
+ onDialogClose(data)} + > + + {renderSubmittedContent()} + + + + +
) }