From eabf0a00dd044fa95645e14f48c8e2a19bf46059 Mon Sep 17 00:00:00 2001 From: Aseer KT Date: Sun, 22 Aug 2021 18:58:30 +0530 Subject: [PATCH] fix: email empty in edit profile route --- client/src/components/FollowModal.tsx | 6 +++- client/src/routes/EditProfile.tsx | 46 ++++++++++++--------------- server/src/resolvers/UserResolver.ts | 1 + 3 files changed, 27 insertions(+), 26 deletions(-) diff --git a/client/src/components/FollowModal.tsx b/client/src/components/FollowModal.tsx index df13ee1..b9f7655 100644 --- a/client/src/components/FollowModal.tsx +++ b/client/src/components/FollowModal.tsx @@ -39,7 +39,11 @@ const FollowModal: React.FC = ({
{data?.getFollows?.map((u) => ( - + ))} {!data?.getFollows || (data.getFollows.length === 0 && ( diff --git a/client/src/routes/EditProfile.tsx b/client/src/routes/EditProfile.tsx index fee10a7..e072291 100644 --- a/client/src/routes/EditProfile.tsx +++ b/client/src/routes/EditProfile.tsx @@ -13,13 +13,7 @@ const EditProfile: React.FC = () => { if (!data) return null; - const { - username, - email, - profile: { name, bio, gender, website }, - } = data.me!; - - if (!username || !email) return null; + const user = data.me!; return ( @@ -36,33 +30,35 @@ const EditProfile: React.FC = () => {
- +
{ try { const res = await editProfile({ variables: values, + update: (cache, { data }) => { + if (data) { + const { errors, ok } = data.editProfile; + if (errors) { + errors.forEach(({ path, message }) => { + action.setFieldError(path, message); + }); + } + if (ok) { + cache.evict({ id: cache.identify(user) }); + setMessage('Profile updated'); + } + } + }, }); - if (res.data) { - const { errors, ok } = res.data.editProfile; - if (errors) { - errors.forEach(({ path, message }) => { - action.setFieldError(path, message); - }); - } - if (ok) { - setMessage('Profile updated'); - } - } - console.log(res); } catch (err) { console.log(err); } diff --git a/server/src/resolvers/UserResolver.ts b/server/src/resolvers/UserResolver.ts index 327e7ae..0b50f6f 100644 --- a/server/src/resolvers/UserResolver.ts +++ b/server/src/resolvers/UserResolver.ts @@ -32,6 +32,7 @@ export class UserResolver { // Field Resolvers @FieldResolver(() => String) + @UseMiddleware(isUser) email(@Root() user: User, @Ctx() { res }: MyContext): string { if (res.locals.username === user.username) { return user.email;