diff --git a/apollo-client.js b/apollo-client.js index 5db8ba03..0474db8f 100644 --- a/apollo-client.js +++ b/apollo-client.js @@ -1,7 +1,6 @@ import { ApolloClient, InMemoryCache, createHttpLink } from "@apollo/client" import { setContext } from '@apollo/client/link/context'; - const API_URL = process.env.NEXT_PUBLIC_API_URL const httpLink = createHttpLink({ @@ -9,7 +8,7 @@ const httpLink = createHttpLink({ }); const authLink = setContext((_, { headers }) => { - const token = localStorage.getItem('token'); + const token = localStorage.getItem("token"); return { headers: { ...headers, @@ -18,7 +17,6 @@ const authLink = setContext((_, { headers }) => { } }); - export const client = new ApolloClient({ cache: new InMemoryCache(), headers: { diff --git a/pages/ajout-demande.tsx b/pages/ajout-demande.tsx index 6a1c4642..9e558ed5 100644 --- a/pages/ajout-demande.tsx +++ b/pages/ajout-demande.tsx @@ -2,7 +2,7 @@ import React, { Fragment, useEffect, useState } from "react"; import { useSession } from "next-auth/react"; import { useLazyQuery, useMutation } from '@apollo/client'; import { client } from "../apollo-client" - +import { useRouter } from "next/router"; import { useStyles } from "tss-react/dsfr"; import { LoggedState } from "../src/components/LoggedState"; import DatabaseApi from "../src/services/api/database"; @@ -24,6 +24,7 @@ import Alert from "@codegouvfr/react-dsfr/Alert"; export default function AjoutDemande() { const { css } = useStyles(); const widthFitContent = css({ width: "fit-content" }) + const router = useRouter() const { status } = useSession() const [isLogged, setLogged] = useState() @@ -33,7 +34,7 @@ export default function AjoutDemande() { const [selectedContactOrigin, setSelectedContactOrigin] = useState() const [selectedContactMode, setSelectedContactMode] = useState() const [selectedContactSupport, setSelectedContactSupport] = useState() - const [contactData, setContactData] = useState() + const [isLoading, setLoading] = useState(false) useEffect(() => { setLogged(status === "authenticated") @@ -53,8 +54,9 @@ export default function AjoutDemande() { const [saveContactRequest] = useMutation( DatabaseApi.SAVE_CONTACT, { client: client, - onCompleted: (data) => { - console.log(data) + onCompleted: () => { + setLoading(false) + goToHome() }, onError: (err) => console.error(err), }); @@ -77,11 +79,18 @@ export default function AjoutDemande() { commentaire: target.comment.value } + setLoading(true) await saveContactRequest({ variables: dataCollected }) } + const goToHome = () => { + router.push({ + pathname: "/", + }) + } + return
@@ -161,7 +170,7 @@ export default function AjoutDemande() { id: "comment" }} /> - + }