Skip to content

Commit

Permalink
fix: email empty in edit profile route
Browse files Browse the repository at this point in the history
  • Loading branch information
aseerkt committed Aug 22, 2021
1 parent d59d416 commit eabf0a0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 26 deletions.
6 changes: 5 additions & 1 deletion client/src/components/FollowModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ const FollowModal: React.FC<FollowModalProps> = ({
</header>
<div className='px-3 overflow-y-auto max-h-96 h-96'>
{data?.getFollows?.map((u) => (
<SuggestionItem darkFollowButton s={u as User} />
<SuggestionItem
key={`follow_${u.id}`}
darkFollowButton
s={u as User}
/>
))}
{!data?.getFollows ||
(data.getFollows.length === 0 && (
Expand Down
46 changes: 21 additions & 25 deletions client/src/routes/EditProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<Container>
Expand All @@ -36,33 +30,35 @@ const EditProfile: React.FC = () => {
</div>
<div className='flex flex-col w-full p-5 md:mx-20'>
<div className='py-4'>
<ChangeProfilePhoto username={username} />
<ChangeProfilePhoto username={user.username} />
</div>
<Formik
initialValues={{
name,
website,
bio,
gender,
email,
name: user.profile.name,
website: user.profile.website,
bio: user.profile.bio,
gender: user.profile.gender,
email: user.email,
}}
onSubmit={async (values, action) => {
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);
}
Expand Down
1 change: 1 addition & 0 deletions server/src/resolvers/UserResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit eabf0a0

Please sign in to comment.