diff --git a/apps/web/pages/settings/my-account/out-of-office/index.tsx b/apps/web/pages/settings/my-account/out-of-office/index.tsx index dc8537fc5041ed..b69c3daff8a3c5 100644 --- a/apps/web/pages/settings/my-account/out-of-office/index.tsx +++ b/apps/web/pages/settings/my-account/out-of-office/index.tsx @@ -1,35 +1,12 @@ -import { Trans } from "next-i18next"; import { useSearchParams } from "next/navigation"; import { useEffect, useState } from "react"; -import { Controller, useForm, useFormState } from "react-hook-form"; -import dayjs from "@calcom/dayjs"; +import { CreateOrEditOutOfOfficeEntryModal } from "@calcom/features/settings/CreateOrEditOutOfOfficeModal"; +import { OutOfOfficeEntriesList } from "@calcom/features/settings/OutOfOfficeEntriesList"; import { getLayout } from "@calcom/features/settings/layouts/SettingsLayout"; -import { useHasTeamPlan } from "@calcom/lib/hooks/useHasPaidPlan"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import { trpc } from "@calcom/trpc/react"; -import useMeQuery from "@calcom/trpc/react/hooks/useMeQuery"; -import { - Button, - DateRangePicker, - Dialog, - DialogContent, - DialogFooter, - DialogHeader, - EmptyScreen, - Icon, - Meta, - Select, - showToast, - SkeletonText, - Switch, - TableBody, - TableCell, - TableNew, - TableRow, - TextArea, - UpgradeTeamsBadge, -} from "@calcom/ui"; +import { Button, Icon, Meta, SkeletonText } from "@calcom/ui"; import PageWrapper from "@components/PageWrapper"; @@ -39,328 +16,7 @@ export type BookingRedirectForm = { toTeamUserId: number | null; reasonId: number; notes?: string; -}; - -const CreateOutOfOfficeEntryModal = ({ - openModal, - closeModal, -}: { - openModal: boolean; - closeModal: () => void; -}) => { - const { t } = useLocale(); - const utils = trpc.useUtils(); - - const [selectedReason, setSelectedReason] = useState<{ label: string; value: number } | null>(null); - const [profileRedirect, setProfileRedirect] = useState(false); - const [selectedMember, setSelectedMember] = useState<{ label: string; value: number | null } | null>(null); - - const [dateRange] = useState<{ startDate: Date; endDate: Date }>({ - startDate: dayjs().utc().startOf("d").toDate(), - endDate: dayjs().utc().add(1, "d").endOf("d").toDate(), - }); - - const { hasTeamPlan } = useHasTeamPlan(); - const { data: listMembers } = trpc.viewer.teams.listMembers.useQuery({}); - const me = useMeQuery(); - const memberListOptions: { - value: number | null; - label: string; - }[] = - listMembers - ?.filter((member) => me?.data?.id !== member.id) - .map((member) => ({ - value: member.id || null, - label: member.name || "", - })) || []; - - const { handleSubmit, setValue, control, register } = useForm({ - defaultValues: { - dateRange: { - startDate: dateRange.startDate, - endDate: dateRange.endDate, - }, - offset: dayjs().utcOffset(), - toTeamUserId: null, - reasonId: 1, - }, - }); - - const createOutOfOfficeEntry = trpc.viewer.outOfOfficeCreate.useMutation({ - onSuccess: () => { - showToast(t("success_entry_created"), "success"); - utils.viewer.outOfOfficeEntriesList.invalidate(); - setProfileRedirect(false); - closeModal(); - }, - onError: (error) => { - showToast(t(error.message), "error"); - }, - }); - - const { data: outOfOfficeReasonList } = trpc.viewer.outOfOfficeReasonList.useQuery(); - - const reasonList = [ - ...(outOfOfficeReasonList || []).map((reason) => ({ - label: `${reason.emoji} ${reason.userId === null ? t(reason.reason) : reason.reason}`, - value: reason.id, - })), - ]; - - return ( - - { - event.preventDefault(); - }}> -
{ - createOutOfOfficeEntry.mutate(data); - setValue("toTeamUserId", null); - setValue("notes", ""); - setSelectedReason(null); - setSelectedMember(null); - })}> -
- -
-

{t("dates")}

-
- ( - { - onChange(values); - }} - /> - )} - /> -
-
- - {/* Reason Select */} -
-
-

{t("reason")}

-