From 1b3f5328b047079eec57c6f89feb46fc67cfdd52 Mon Sep 17 00:00:00 2001 From: Eric Date: Sun, 11 Dec 2022 19:00:47 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/admin.tsx | 8 +++++--- pages/api/user/get-current.ts | 2 +- pages/api/user/index.ts | 2 +- pages/api/user/update-gift.ts | 5 ++++- pages/mon-compte.tsx | 6 ++++-- 5 files changed, 15 insertions(+), 8 deletions(-) diff --git a/pages/admin.tsx b/pages/admin.tsx index fc20a87..01cfdc2 100644 --- a/pages/admin.tsx +++ b/pages/admin.tsx @@ -200,9 +200,11 @@ const Admin = (props: Props) => { const changeGiftStatus = async (gain: Gain) => { const body = { gain } fetcher('/api/user/update-gift', 'PUT', body) - console.log('g', gain); + setTimeout(() => { + router.refresh(); + }, 2000) - setCurrentUserGain(gain) + // setCurrentUserGain(gain) // router.refresh(); }; @@ -278,7 +280,7 @@ const Admin = (props: Props) => {

-

{currentUser?.email || 'utilisateur'}

+

{currentUser?.email || 'utilisateur'}


{currentUser &&
diff --git a/pages/api/user/get-current.ts b/pages/api/user/get-current.ts index 6a8cfac..a958f66 100644 --- a/pages/api/user/get-current.ts +++ b/pages/api/user/get-current.ts @@ -22,7 +22,7 @@ export default async function getCurrent(req: NextApiRequest, res: NextApiRespon selectedUserPhoneNumber, } = req.body; // est-ce la méthode est un POST ou PUT? - if (req.method !== ("POST" || "PUT")) { + if (!(['POST', 'PUT'].indexOf(req.method) > -1)) { throw new Error( `The HTTP ${req.method} method is not supported at this route.` ); diff --git a/pages/api/user/index.ts b/pages/api/user/index.ts index 036daa0..53e5c29 100644 --- a/pages/api/user/index.ts +++ b/pages/api/user/index.ts @@ -7,7 +7,7 @@ export default async function updateOrCreate(req: NextApiRequest, res: NextApiRe const { address, name, phoneNumber, surname, zipCode } = req.body; // est-ce la méthode est un POST ou PUT? - if (req.method !== ("POST" || "PUT")) { + if (!(['POST', 'PUT'].indexOf(req.method) > -1)) { throw new Error( `The HTTP ${req.method} method is not supported at this route.` ); diff --git a/pages/api/user/update-gift.ts b/pages/api/user/update-gift.ts index 57f0992..4345ba2 100644 --- a/pages/api/user/update-gift.ts +++ b/pages/api/user/update-gift.ts @@ -10,8 +10,11 @@ export default async function updtateGift(req: NextApiRequest, res: NextApiRespo const session = await getSession({ req }) const { gain } = req.body; + console.log(req.method); + + // est-ce la méthode est un POST ou PUT? - if (req.method !== ("POST" || 'PUT')) { + if (!(['POST', 'PUT'].indexOf(req.method) > -1)) { throw new Error( `The HTTP ${req.method} method is not supported at this route.` ); diff --git a/pages/mon-compte.tsx b/pages/mon-compte.tsx index 9e135e0..184baf1 100644 --- a/pages/mon-compte.tsx +++ b/pages/mon-compte.tsx @@ -48,7 +48,7 @@ export async function getServerSideProps(context) { return { props: { user: JSON.parse(JSON.stringify(user)), - userGains, + userGains: JSON.parse(JSON.stringify(userGains)), }, } } @@ -223,11 +223,13 @@ const MonCompte = (props: Props) => { {props.userGains.map((info: any, index: number) => { + console.log('ii', info); + return {++index} {info.codeCadeau} {info.produit.nomProduit} - {!info.produit.retrait ? '❌ déja récupéré' : '✔️ venir me chercher !'} + {info.retrait ? '❌ déja récupéré' : '✔️ venir me chercher !'} })}