Skip to content
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

fix: event type back button #15722

Merged
merged 2 commits into from
Jul 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 34 additions & 35 deletions apps/web/modules/event-types/views/event-types-single-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import { telemetryEventTypes, useTelemetry } from "@calcom/lib/telemetry";
import { validateBookerLayouts } from "@calcom/lib/validateBookerLayouts";
import type { Prisma } from "@calcom/prisma/client";
import { SchedulingType } from "@calcom/prisma/enums";
import type { customInputSchema, EventTypeMetaDataSchema } from "@calcom/prisma/zod-utils";
import { eventTypeBookingFields } from "@calcom/prisma/zod-utils";
import type { RouterOutputs } from "@calcom/trpc/react";
Expand Down Expand Up @@ -118,7 +117,7 @@

const ManagedEventTypeDialog = dynamic(() => import("@components/eventtype/ManagedEventDialog"));

const AssignmentWarningDialog = dynamic(() => import("@components/eventtype/AssignmentWarningDialog"));

Check warning on line 120 in apps/web/modules/event-types/views/event-types-single-view.tsx

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

apps/web/modules/event-types/views/event-types-single-view.tsx#L120

[@typescript-eslint/no-unused-vars] 'AssignmentWarningDialog' is assigned a value but never used. Allowed unused vars must match /^_/u.

export type Host = { isFixed: boolean; userId: number; priority: number };

Expand Down Expand Up @@ -224,9 +223,9 @@
});

const { eventType, locationOptions, team, teamMembers, currentUserMembership, destinationCalendar } = props;
const [isOpenAssignmentWarnDialog, setIsOpenAssignmentWarnDialog] = useState<boolean>(false);

Check warning on line 226 in apps/web/modules/event-types/views/event-types-single-view.tsx

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

apps/web/modules/event-types/views/event-types-single-view.tsx#L226

[@typescript-eslint/no-unused-vars] 'isOpenAssignmentWarnDialog' is assigned a value but never used. Allowed unused elements of array destructuring patterns must match /^_/u.

Check warning on line 226 in apps/web/modules/event-types/views/event-types-single-view.tsx

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

apps/web/modules/event-types/views/event-types-single-view.tsx#L226

[@typescript-eslint/no-unused-vars] 'setIsOpenAssignmentWarnDialog' is assigned a value but never used. Allowed unused elements of array destructuring patterns must match /^_/u.
const [pendingRoute, setPendingRoute] = useState("");

Check warning on line 227 in apps/web/modules/event-types/views/event-types-single-view.tsx

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

apps/web/modules/event-types/views/event-types-single-view.tsx#L227

[@typescript-eslint/no-unused-vars] 'pendingRoute' is assigned a value but never used. Allowed unused elements of array destructuring patterns must match /^_/u.

Check warning on line 227 in apps/web/modules/event-types/views/event-types-single-view.tsx

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

apps/web/modules/event-types/views/event-types-single-view.tsx#L227

[@typescript-eslint/no-unused-vars] 'setPendingRoute' is assigned a value but never used. Allowed unused elements of array destructuring patterns must match /^_/u.
const leaveWithoutAssigningHosts = useRef(false);

Check warning on line 228 in apps/web/modules/event-types/views/event-types-single-view.tsx

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

apps/web/modules/event-types/views/event-types-single-view.tsx#L228

[@typescript-eslint/no-unused-vars] 'leaveWithoutAssigningHosts' is assigned a value but never used. Allowed unused vars must match /^_/u.
const [animationParentRef] = useAutoAnimate<HTMLDivElement>();
const updateMutation = trpc.viewer.eventTypes.update.useMutation({
onSuccess: async () => {
Expand Down Expand Up @@ -269,7 +268,7 @@
},
});

const router = useRouter();

Check warning on line 271 in apps/web/modules/event-types/views/event-types-single-view.tsx

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

apps/web/modules/event-types/views/event-types-single-view.tsx#L271

[@typescript-eslint/no-unused-vars] 'router' is assigned a value but never used. Allowed unused vars must match /^_/u.

const [periodDates] = useState<{ startDate: Date; endDate: Date }>({
startDate: new Date(eventType.periodStartDate || Date.now()),
Expand Down Expand Up @@ -401,40 +400,40 @@
formState: { isDirty: isFormDirty, dirtyFields },
} = formMethods;

useEffect(() => {
const handleRouteChange = (url: string) => {
const paths = url.split("/");

// Check if event is managed event type - skip if there is assigned users
const assignedUsers = eventType.children;
const isManagedEventType = eventType.schedulingType === SchedulingType.MANAGED;
if (eventType.assignAllTeamMembers) {
return;
} else if (isManagedEventType && assignedUsers.length > 0) {
return;
}

const hosts = eventType.hosts;
if (
!leaveWithoutAssigningHosts.current &&
!!team &&
(hosts.length === 0 || assignedUsers.length === 0) &&
(url === "/event-types" || paths[1] !== "event-types")
) {
setIsOpenAssignmentWarnDialog(true);
setPendingRoute(url);
router.events.emit(
"routeChangeError",
new Error(`Aborted route change to ${url} because none was assigned to team event`)
);
throw "Aborted";
}
};
router.events.on("routeChangeStart", handleRouteChange);
return () => {
router.events.off("routeChangeStart", handleRouteChange);
};
}, [router]);
// useEffect(() => {
// const handleRouteChange = (url: string) => {
// const paths = url.split("/");
//
// // Check if event is managed event type - skip if there is assigned users
// const assignedUsers = eventType.children;
// const isManagedEventType = eventType.schedulingType === SchedulingType.MANAGED;
// if (eventType.assignAllTeamMembers) {
// return;
// } else if (isManagedEventType && assignedUsers.length > 0) {
// return;
// }
//
// const hosts = eventType.hosts;
// if (
// !leaveWithoutAssigningHosts.current &&
// !!team &&
// (hosts.length === 0 || assignedUsers.length === 0) &&
// (url === "/event-types" || paths[1] !== "event-types")
// ) {
// setIsOpenAssignmentWarnDialog(true);
// setPendingRoute(url);
// router.events.emit(
// "routeChangeError",
// new Error(`Aborted route change to ${url} because none was assigned to team event`)
// );
// throw "Aborted";
// }
// };
// router.events.on("routeChangeStart", handleRouteChange);
// return () => {
// router.events.off("routeChangeStart", handleRouteChange);
// };
// }, [router]);

const appsMetadata = formMethods.getValues("metadata")?.apps;
const availability = formMethods.watch("availability");
Expand Down
Loading