Skip to content

Commit

Permalink
fix: apply feedback updates
Browse files Browse the repository at this point in the history
  • Loading branch information
yassinedorbozgithub committed Jan 21, 2025
1 parent b7da483 commit 3b2f070
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions frontend/src/hooks/useDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import { DialogProps } from "@mui/material";
import { useState } from "react";
import { Dispatch, SetStateAction, useState } from "react";

export type DialogControlProps<T, C = never> = Omit<
DialogControl<T, C>,
Expand All @@ -20,7 +20,7 @@ type TCloseDialog = <E extends React.MouseEvent | Event | Object>(
type TFnVoid<T> = (data?: T) => void;
export type DialogControl<T = null, C = never> = DialogProps & {
data?: T;
saveData?: TFnVoid<T>;
setData?: Dispatch<SetStateAction<T | undefined>>;
callback?: TFnVoid<C>;
openDialog: TFnVoid<T>;
closeDialog: TCloseDialog;
Expand All @@ -34,12 +34,15 @@ export const useDialog = <T,>(initialState: boolean): DialogControl<T> => {
setOpen(true);
};
const closeDialog: TCloseDialog = (event, reason) => {
if (reason === "postDelete") setData(undefined);
if (reason !== "backdropClick") setOpen(false);
if (reason === "postDelete") {
setData(undefined);
}
if (reason !== "backdropClick") {
setOpen(false);
}
};
const saveData: TFnVoid<T> = (data) => setData(data);

return { open, openDialog, closeDialog, data, saveData };
return { open, openDialog, closeDialog, data, setData };
};

export const getDisplayDialogs = <T,>({
Expand Down

0 comments on commit 3b2f070

Please sign in to comment.