feat: trpc v10 migration (#5332)
* migrate router * createTRPCReact * frontend 1 * random format change * frontend 2 * withQuery * form router * TS-ERROR: proxy on utils-client * inferance * ssg * reuse * trpc rc4 * Apply suggestions from code review * skip test * move skip one level up * whops * rc 6 with new setData func Co-authored-by: zomars <[email protected]>
This commit is contained in:
1 parent
6d67808627
commit
db7c3fb52f
157 files changed
+3062
-3144
No files matched your search
@@ -9,7 +9,7 @@ import { Dialog } from "@calcom/ui/v2/core/Dialog";
|
||||
|
||||
export default function TimezoneChangeDialog() {
|
||||
const { t } = useLocale();
|
||||
const { data: user, isLoading } = trpc.useQuery(["viewer.me"]);
|
||||
const { data: user, isLoading } = trpc.viewer.me.useQuery();
|
||||
const utils = trpc.useContext();
|
||||
const userTz = user?.timeZone;
|
||||
const currentTz = dayjs.tz.guess();
|
||||
@@ -18,7 +18,7 @@ export default function TimezoneChangeDialog() {
|
||||
// update user settings
|
||||
const onSuccessMutation = async () => {
|
||||
showToast(t("updated_timezone_to", { formattedCurrentTz }), "success");
|
||||
await utils.invalidateQueries(["viewer.me"]);
|
||||
await utils.viewer.me.invalidate();
|
||||
};
|
||||
|
||||
const onErrorMutation = () => {
|
||||
@@ -26,7 +26,7 @@ export default function TimezoneChangeDialog() {
|
||||
};
|
||||
|
||||
// update timezone in db
|
||||
const mutation = trpc.useMutation("viewer.updateProfile", {
|
||||
const mutation = trpc.viewer.updateProfile.useMutation({
|
||||
onSuccess: onSuccessMutation,
|
||||
onError: onErrorMutation,
|
||||
});
|
||||
|
||||
@@ -216,9 +216,9 @@ function UserDropdown({ small }: { small?: boolean }) {
|
||||
screenResolution: `${screen.width}x${screen.height}`,
|
||||
});
|
||||
});
|
||||
const mutation = trpc.useMutation("viewer.away", {
|
||||
const mutation = trpc.viewer.away.useMutation({
|
||||
onSettled() {
|
||||
utils.invalidateQueries("viewer.me");
|
||||
utils.viewer.me.invalidate();
|
||||
},
|
||||
});
|
||||
const utils = trpc.useContext();
|
||||
@@ -298,7 +298,7 @@ function UserDropdown({ small }: { small?: boolean }) {
|
||||
<button
|
||||
onClick={() => {
|
||||
mutation.mutate({ away: !user?.away });
|
||||
utils.invalidateQueries("viewer.me");
|
||||
utils.viewer.me.invalidate();
|
||||
}}
|
||||
className="flex min-w-max cursor-pointer items-center px-4 py-2 text-sm hover:bg-gray-100 hover:text-gray-900">
|
||||
<Icon.FiMoon
|
||||
@@ -554,9 +554,13 @@ const Navigation = () => {
|
||||
|
||||
function useShouldDisplayNavigationItem(item: NavigationItemType) {
|
||||
const { status } = useSession();
|
||||
const { data: routingForms } = trpc.useQuery(["viewer.appById", { appId: "routing-forms" }], {
|
||||
enabled: status === "authenticated" && requiredCredentialNavigationItems.includes(item.name),
|
||||
});
|
||||
const { data: routingForms } = trpc.viewer.appById.useQuery(
|
||||
{ appId: "routing-forms" },
|
||||
{
|
||||
enabled: status === "authenticated" && requiredCredentialNavigationItems.includes(item.name),
|
||||
trpc: {},
|
||||
}
|
||||
);
|
||||
return !requiredCredentialNavigationItems.includes(item.name) || routingForms?.isInstalled;
|
||||
}
|
||||
|
||||
|
||||
@@ -47,10 +47,10 @@ export default function InstalledAppsLayout({
|
||||
children,
|
||||
...rest
|
||||
}: { children: React.ReactNode } & ComponentProps<typeof Shell>) {
|
||||
const query = trpc.useQuery([
|
||||
"viewer.integrations",
|
||||
{ variant: InstalledAppVariants.payment, onlyInstalled: true },
|
||||
]);
|
||||
const query = trpc.viewer.integrations.useQuery({
|
||||
variant: InstalledAppVariants.payment,
|
||||
onlyInstalled: true,
|
||||
});
|
||||
let actualTabs = tabs;
|
||||
if (query.data?.items.length === 0) {
|
||||
actualTabs = tabs.filter((tab) => tab.name !== InstalledAppVariants.payment);
|
||||
|
||||
@@ -110,7 +110,7 @@ const SettingsSidebarContainer = ({ className = "" }) => {
|
||||
const [teamMenuState, setTeamMenuState] =
|
||||
useState<{ teamId: number | undefined; teamMenuOpen: boolean }[]>();
|
||||
|
||||
const { data: teams } = trpc.useQuery(["viewer.teams.list"]);
|
||||
const { data: teams } = trpc.viewer.teams.list.useQuery();
|
||||
|
||||
useEffect(() => {
|
||||
if (teams) {
|
||||
|
||||
@@ -25,7 +25,7 @@ export default function SAMLLogin({ samlTenantID, samlProductID, setErrorMessage
|
||||
const methods = useFormContext();
|
||||
const telemetry = useTelemetry();
|
||||
|
||||
const mutation = trpc.useMutation("viewer.public.samlTenantProduct", {
|
||||
const mutation = trpc.viewer.public.samlTenantProduct.useMutation({
|
||||
onSuccess: async (data) => {
|
||||
await signIn("saml", {}, { tenant: data.tenant, product: data.product });
|
||||
},
|
||||
|
||||
@@ -62,7 +62,7 @@ export default function CreateEventTypeButton(props: CreateEventTypeBtnProps) {
|
||||
const form = useForm<z.infer<typeof createEventTypeInput>>({
|
||||
resolver: zodResolver(createEventTypeInput),
|
||||
});
|
||||
const { setValue, watch, register } = form;
|
||||
const { setValue, register } = form;
|
||||
|
||||
useEffect(() => {
|
||||
if (!router.isReady) return;
|
||||
@@ -84,7 +84,7 @@ export default function CreateEventTypeButton(props: CreateEventTypeBtnProps) {
|
||||
// If query params change, update the form
|
||||
}, [router.isReady, router.query, setValue]);
|
||||
|
||||
const createMutation = trpc.useMutation("viewer.eventTypes.create", {
|
||||
const createMutation = trpc.viewer.eventTypes.create.useMutation({
|
||||
onSuccess: async ({ eventType }) => {
|
||||
await router.replace("/event-types/" + eventType.id);
|
||||
showToast(t("event_type_created_successfully", { eventTypeTitle: eventType.title }), "success");
|
||||
@@ -345,13 +345,10 @@ function CreateEventTeamsItem(props: {
|
||||
option: EventTypeParent;
|
||||
}) {
|
||||
const session = useSession();
|
||||
const membershipQuery = trpc.useQuery([
|
||||
"viewer.teams.getMembershipbyUser",
|
||||
{
|
||||
memberId: session.data?.user?.id as number,
|
||||
teamId: props.option.teamId as number,
|
||||
},
|
||||
]);
|
||||
const membershipQuery = trpc.viewer.teams.getMembershipbyUser.useQuery({
|
||||
memberId: session.data?.user?.id as number,
|
||||
teamId: props.option.teamId as number,
|
||||
});
|
||||
|
||||
const isDisabled = membershipQuery.data?.role === "MEMBER";
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ export default function DisconnectIntegration({
|
||||
const { t } = useLocale();
|
||||
const [modalOpen, setModalOpen] = useState(false);
|
||||
|
||||
const mutation = trpc.useMutation("viewer.deleteCredential", {
|
||||
const mutation = trpc.viewer.deleteCredential.useMutation({
|
||||
onSuccess: () => {
|
||||
showToast(t("app_removed_successfully"), "success");
|
||||
setModalOpen(false);
|
||||
|
||||
@@ -21,16 +21,16 @@ export default function TeamSettingsRightSidebar(props: { team: TeamWithMembers;
|
||||
|
||||
const permalink = `${process.env.NEXT_PUBLIC_WEBSITE_URL}/team/${props.team?.slug}`;
|
||||
|
||||
const deleteTeamMutation = trpc.useMutation("viewer.teams.delete", {
|
||||
const deleteTeamMutation = trpc.viewer.teams.delete.useMutation({
|
||||
async onSuccess() {
|
||||
await utils.invalidateQueries(["viewer.teams.get"]);
|
||||
await utils.viewer.teams.get.invalidate();
|
||||
router.push(`/settings/teams`);
|
||||
showToast(t("your_team_updated_successfully"), "success");
|
||||
},
|
||||
});
|
||||
const acceptOrLeaveMutation = trpc.useMutation("viewer.teams.acceptOrLeave", {
|
||||
const acceptOrLeaveMutation = trpc.viewer.teams.acceptOrLeave.useMutation({
|
||||
onSuccess: () => {
|
||||
utils.invalidateQueries(["viewer.teams.list"]);
|
||||
utils.viewer.teams.list.invalidate();
|
||||
router.push(`/settings/teams`);
|
||||
},
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user