From 50904d25887a124875059379c3f2c0b5be9db223 Mon Sep 17 00:00:00 2001 From: Hariom Balhara Date: Thu, 6 Oct 2022 19:07:52 +0530 Subject: [PATCH] useForm defaultValues should be available initially (#4863) Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> --- .../pages/v2/settings/my-account/general.tsx | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/apps/web/pages/v2/settings/my-account/general.tsx b/apps/web/pages/v2/settings/my-account/general.tsx index d2881f42dc..9d0b041062 100644 --- a/apps/web/pages/v2/settings/my-account/general.tsx +++ b/apps/web/pages/v2/settings/my-account/general.tsx @@ -4,7 +4,7 @@ import { useForm, Controller } from "react-hook-form"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import { setIs24hClockInLocalStorage } from "@calcom/lib/timeFormat"; -import { trpc } from "@calcom/trpc/react"; +import { inferQueryOutput, trpc } from "@calcom/trpc/react"; import { Button } from "@calcom/ui/v2/core/Button"; import Meta from "@calcom/ui/v2/core/Meta"; import TimezoneSelect from "@calcom/ui/v2/core/TimezoneSelect"; @@ -34,25 +34,32 @@ const SkeletonLoader = () => { interface GeneralViewProps { localeProp: string; + user: inferQueryOutput<"viewer.me">; } const WithQuery = withQuery(["viewer.public.i18n"], { trpc: { context: { skipBatch: true } } }); const GeneralQueryView = () => { + const { t } = useLocale(); + + const { data: user, isLoading } = trpc.useQuery(["viewer.me"]); + if (isLoading) return ; + if (!user) { + throw new Error(t("something_went_wrong")); + } return ( } + success={({ data }) => } customLoader={} /> ); }; -const GeneralView = ({ localeProp }: GeneralViewProps) => { +const GeneralView = ({ localeProp, user }: GeneralViewProps) => { const router = useRouter(); const utils = trpc.useContext(); const { t } = useLocale(); - const { data: user, isLoading } = trpc.useQuery(["viewer.me"]); const mutation = trpc.useMutation("viewer.updateProfile", { onSuccess: () => { showToast(t("settings_updated_successfully"), "success"); @@ -93,20 +100,18 @@ const GeneralView = ({ localeProp }: GeneralViewProps) => { value: localeProp || "", label: localeOptions.find((option) => option.value === localeProp)?.label || "", }, - timeZone: user?.timeZone || "", + timeZone: user.timeZone || "", timeFormat: { - value: user?.timeFormat || 12, - label: timeFormatOptions.find((option) => option.value === user?.timeFormat)?.label || 12, + value: user.timeFormat || 12, + label: timeFormatOptions.find((option) => option.value === user.timeFormat)?.label || 12, }, weekStart: { - value: user?.weekStart, - label: nameOfDay(localeProp, user?.weekStart === "Sunday" ? 0 : 1), + value: user.weekStart, + label: nameOfDay(localeProp, user.weekStart === "Sunday" ? 0 : 1), }, }, }); - if (isLoading) return ; - return (