-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes for avatar payloads #5921
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Self review done
| "timeFormat" | ||
| "metadata" | ||
>; | ||
user: Pick<User, "username" | "metadata">; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Picking only needed fields
| "timeFormat" | ||
| "metadata" | ||
>; | ||
user: Pick<User, "username" | "metadata">; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
import { getPlaceholderAvatar } from "@calcom/lib/getPlaceholderAvatar"; | ||
import prisma from "@calcom/prisma"; | ||
|
||
import { defaultAvatarSrc } from "@lib/profile"; | ||
|
||
export default async function handler(req: NextApiRequest, res: NextApiResponse) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This endpoint was pretty hard to read, I hope this improves legibility a bit.
const { data: user, isLoading } = trpc.viewer.me.useQuery(); | ||
const { data: avatar, isLoading: isLoadingAvatar } = trpc.viewer.avatar.useQuery(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We fetch raw avatar in separate endpoint
utils.viewer.me.invalidate(); | ||
utils.viewer.avatar.invalidate(); | ||
setTempFormValues(null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To avoid stale data
// TODO: Setting avatar value to /avatar.png(which is a dynamic route) would actually reset the avatar because /avatar.png is supposed to return the value of user.avatar | ||
// if (user.avatar) user.avatar = `${CAL_URL}/${user.username}/avatar.png`; | ||
const avatar = user.avatar || defaultAvatarSrc({ email }); | ||
user.avatar = rawAvatar ? `${WEBAPP_URL}/${user.username}/avatar.png` : defaultAvatarSrc({ email }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hopefully this set the nail in the coffin from #5299
@@ -160,7 +158,7 @@ const loggedInViewerRouter = router({ | |||
locale: user.locale, | |||
timeFormat: user.timeFormat, | |||
timeZone: user.timeZone, | |||
avatar: `${CAL_URL}/${user.username}/avatar.png`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is already handled in createContext
avatar: authedProcedure.query(({ ctx }) => ({ | ||
avatar: ctx.user.rawAvatar, | ||
})), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Basic query to fetch raw avatar data.
@@ -1,12 +1,12 @@ | |||
import React, { forwardRef, ReactElement, ReactNode, Ref, useCallback, useId, useState } from "react"; | |||
import { Edit2, Eye, EyeOff } from "react-feather"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused
import { FieldValues, FormProvider, SubmitHandler, useFormContext, UseFormReturn } from "react-hook-form"; | ||
|
||
import classNames from "@calcom/lib/classNames"; | ||
import { getErrorFromUnknown } from "@calcom/lib/errors"; | ||
import { useLocale } from "@calcom/lib/hooks/useLocale"; | ||
|
||
import { Alert, showToast, Icon, Skeleton, Tooltip, UnstyledSelect } from "../../.."; | ||
import { Alert, Icon, showToast, Skeleton, Tooltip, UnstyledSelect } from "../../.."; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorted imports
What does this PR do?
Builds upon #5299
viewer.me
/api/avatar
endpointType of change
How should this be tested?