-
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
chore: app router - /event-types pages #18181
base: main
Are you sure you want to change the base?
Changes from 4 commits
aef1705
3a72d31
09f9833
01568aa
8efb797
2721da4
5a73373
d8a0fd6
a4b7f35
d033bd8
80aca22
76287f1
fd3fecf
0c28ff2
4e5cdf3
4d083f5
ef08a5a
4a44961
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,10 +3,6 @@ | |
import type { AppRouterInstance } from "next/dist/shared/lib/app-router-context.shared-runtime"; | ||
import dynamic from "next/dynamic"; | ||
import { usePathname, useRouter as useAppRouter } from "next/navigation"; | ||
// eslint-disable-next-line @calcom/eslint/deprecated-imports-next-router | ||
import { useRouter as usePageRouter } from "next/router"; | ||
// eslint-disable-next-line @calcom/eslint/deprecated-imports-next-router | ||
import type { NextRouter as NextPageRouter } from "next/router"; | ||
import { useEffect, useRef, useState } from "react"; | ||
import { z } from "zod"; | ||
|
||
|
@@ -89,71 +85,34 @@ const EventAITab = dynamic(() => | |
|
||
export type EventTypeWebWrapperProps = { | ||
id: number; | ||
isAppDir?: boolean; | ||
}; | ||
|
||
// discriminative factor: isAppDir | ||
type EventTypeAppComponentProp = { | ||
id: number; | ||
isAppDir: true; | ||
pathname: string; | ||
pageRouter: null; | ||
appRouter: AppRouterInstance; | ||
}; | ||
|
||
// discriminative factor: isAppDir | ||
type EventTypePageComponentProp = { | ||
id: number; | ||
isAppDir: false; | ||
pageRouter: NextPageRouter; | ||
pathname: null; | ||
appRouter: null; | ||
}; | ||
|
||
type EventTypeAppPageComponentProp = EventTypeAppComponentProp | EventTypePageComponentProp; | ||
|
||
export const EventTypeWebWrapper = ({ id, isAppDir }: EventTypeWebWrapperProps & { isAppDir?: boolean }) => { | ||
export const EventTypeWebWrapper = ({ id }: EventTypeWebWrapperProps) => { | ||
const { data: eventTypeQueryData } = trpc.viewer.eventTypes.get.useQuery({ id }); | ||
|
||
if (!eventTypeQueryData) return null; | ||
|
||
return isAppDir ? ( | ||
<EventTypeAppWrapper {...eventTypeQueryData} id={id} /> | ||
) : ( | ||
<EventTypePageWrapper {...eventTypeQueryData} id={id} /> | ||
); | ||
}; | ||
|
||
const EventTypePageWrapper = ({ id, ...rest }: EventTypeSetupProps & { id: number }) => { | ||
const router = usePageRouter(); | ||
return ( | ||
<EventTypeWeb {...rest} id={id} isAppDir={false} pageRouter={router} pathname={null} appRouter={null} /> | ||
); | ||
return <EventTypeAppWrapper {...eventTypeQueryData} id={id} />; | ||
}; | ||
|
||
const EventTypeAppWrapper = ({ id, ...rest }: EventTypeSetupProps & { id: number }) => { | ||
const pathname = usePathname(); | ||
const router = useAppRouter(); | ||
return ( | ||
<EventTypeWeb | ||
{...rest} | ||
id={id} | ||
isAppDir={true} | ||
pathname={pathname ?? ""} | ||
pageRouter={null} | ||
appRouter={router} | ||
/> | ||
); | ||
return <EventTypeWeb {...rest} id={id} pathname={pathname ?? ""} appRouter={router} />; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can shift this logic in EventTypeWebWrapper directly and remove this component completely There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. on it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. addressed |
||
}; | ||
|
||
const EventTypeWeb = ({ | ||
id, | ||
isAppDir, | ||
pageRouter, | ||
appRouter, | ||
pathname, | ||
...rest | ||
}: EventTypeSetupProps & EventTypeAppPageComponentProp) => { | ||
}: EventTypeSetupProps & EventTypeAppComponentProp) => { | ||
const { t } = useLocale(); | ||
const utils = trpc.useUtils(); | ||
|
||
|
@@ -281,7 +240,7 @@ const EventTypeWeb = ({ | |
} as const; | ||
|
||
useHandleRouteChange({ | ||
watchTrigger: isAppDir ? pageRouter : pathname, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. seems like we used an opposite conditional here |
||
watchTrigger: pathname, | ||
isTeamEventTypeDeleted: isTeamEventTypeDeleted.current, | ||
isleavingWithoutAssigningHosts: leaveWithoutAssigningHosts.current, | ||
isTeamEventType: !!team, | ||
|
@@ -292,22 +251,10 @@ const EventTypeWeb = ({ | |
onError: (url) => { | ||
setIsOpenAssignmentWarnDialog(true); | ||
setPendingRoute(url); | ||
if (!isAppDir) { | ||
pageRouter.events.emit( | ||
"routeChangeError", | ||
new Error(`Aborted route change to ${url} because none was assigned to team event`) | ||
); | ||
throw "Aborted"; | ||
} | ||
|
||
if (isAppDir) throw new Error(`Aborted route change to ${url} because none was assigned to team event`); | ||
throw new Error(`Aborted route change to ${url} because none was assigned to team event`); | ||
}, | ||
onStart: (handleRouteChange) => { | ||
!isAppDir && pageRouter.events.on("routeChangeStart", handleRouteChange); | ||
isAppDir && handleRouteChange(pathname || ""); | ||
}, | ||
onEnd: (handleRouteChange) => { | ||
!isAppDir && pageRouter.events.off("routeChangeStart", handleRouteChange); | ||
handleRouteChange(pathname || ""); | ||
}, | ||
}); | ||
|
||
|
@@ -370,7 +317,7 @@ const EventTypeWeb = ({ | |
await utils.viewer.eventTypes.invalidate(); | ||
showToast(t("event_type_deleted_successfully"), "success"); | ||
isTeamEventTypeDeleted.current = true; | ||
isAppDir ? appRouter.push("/event-types") : pageRouter.push("/event-types"); | ||
appRouter.push("/event-types"); | ||
setSlugExistsChildrenDialogOpen([]); | ||
setIsOpenAssignmentWarnDialog(false); | ||
}, | ||
|
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.
Confirmed that these are not imported from this file anywhere