fix: keep dialog state by decoupling it from list (#24914)
Co-authored-by: Udit Takkar <[email protected]>
This commit is contained in:
1 parent
c741d8133e
commit
c6ab6b3d13
4 files changed
+94
-61
No files matched your search
@@ -0,0 +1,56 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
import { useCompatSearchParams } from "@calcom/lib/hooks/useCompatSearchParams";
|
||||
|
||||
import OutOfOfficeEntriesList from "@calcom/features/settings/outOfOffice/OutOfOfficeEntriesList";
|
||||
import { CreateOrEditOutOfOfficeEntryModal } from "@calcom/features/settings/outOfOffice/CreateOrEditOutOfOfficeModal";
|
||||
import type { BookingRedirectForm } from "@calcom/features/settings/outOfOffice/CreateOrEditOutOfOfficeModal";
|
||||
|
||||
export default function OutOfOfficeView() {
|
||||
const [openModal, setOpenModal] = useState(false);
|
||||
const [currentlyEditingOutOfOfficeEntry, setCurrentlyEditingOutOfOfficeEntry] =
|
||||
useState<BookingRedirectForm | null>(null);
|
||||
|
||||
const params = useCompatSearchParams();
|
||||
const openModalOnStart = !!params?.get("om");
|
||||
|
||||
useEffect(() => {
|
||||
if (openModalOnStart) {
|
||||
setOpenModal(true);
|
||||
}
|
||||
}, [openModalOnStart]);
|
||||
|
||||
const handleOpenCreateDialog = () => {
|
||||
setCurrentlyEditingOutOfOfficeEntry(null);
|
||||
setOpenModal(true);
|
||||
};
|
||||
|
||||
const handleOpenEditDialog = (entry: BookingRedirectForm) => {
|
||||
setCurrentlyEditingOutOfOfficeEntry(entry);
|
||||
setOpenModal(true);
|
||||
};
|
||||
|
||||
const handleCloseModal = () => {
|
||||
setOpenModal(false);
|
||||
setCurrentlyEditingOutOfOfficeEntry(null);
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<OutOfOfficeEntriesList
|
||||
onOpenCreateDialog={handleOpenCreateDialog}
|
||||
onOpenEditDialog={handleOpenEditDialog}
|
||||
/>
|
||||
{openModal && (
|
||||
<CreateOrEditOutOfOfficeEntryModal
|
||||
openModal={openModal}
|
||||
closeModal={handleCloseModal}
|
||||
currentlyEditingOutOfOfficeEntry={currentlyEditingOutOfOfficeEntry}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user