From 27422c351c5d080f893e041afda37296e4801149 Mon Sep 17 00:00:00 2001 From: Syed Ali Shahbaz <52925846+alishaz-polymath@users.noreply.github.com> Date: Mon, 23 May 2022 16:47:00 +0530 Subject: [PATCH] Fix UI of dialog (#2788) * removed large mandatory height and scroll * added z index using css * cleanup * fixed TS errors * extract dialog out of dropdown * Adds custom loading text to confirmation dialog * rename update * utilizing mutation loading state Co-authored-by: Peer Richelsen Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> --- .../dialog/ConfirmationDialogContent.tsx | 4 +- apps/web/pages/event-types/index.tsx | 117 ++++++++---------- packages/ui/Dialog.tsx | 2 +- 3 files changed, 57 insertions(+), 66 deletions(-) diff --git a/apps/web/components/dialog/ConfirmationDialogContent.tsx b/apps/web/components/dialog/ConfirmationDialogContent.tsx index 6337b41d..ec77e781 100644 --- a/apps/web/components/dialog/ConfirmationDialogContent.tsx +++ b/apps/web/components/dialog/ConfirmationDialogContent.tsx @@ -12,6 +12,7 @@ export type ConfirmationDialogContentProps = { confirmBtnText?: string; cancelBtnText?: string; isLoading?: boolean; + loadingText?: string; onConfirm?: (event: React.MouseEvent) => void; title: string; variety?: "danger" | "warning" | "success"; @@ -25,6 +26,7 @@ export default function ConfirmationDialogContent(props: PropsWithChildren {confirmBtn || ( )} diff --git a/apps/web/pages/event-types/index.tsx b/apps/web/pages/event-types/index.tsx index 6c3dd0bd..8dd740e1 100644 --- a/apps/web/pages/event-types/index.tsx +++ b/apps/web/pages/event-types/index.tsx @@ -87,12 +87,12 @@ const Item = ({ type, group, readOnly }: { type: EventType; group: EventTypeGrou data-testid={"event-type-slug-" + type.id}>{`/${group.profile.slug}/${type.slug}`} {type.hidden && ( - {t("hidden")} + {t("hidden") as string} )} {readOnly && ( - {t("readonly")} + {t("readonly") as string} )} @@ -107,7 +107,8 @@ const MemoizedItem = React.memo(Item); export const EventTypeList = ({ group, groupIndex, readOnly, types }: EventTypeListProps): JSX.Element => { const { t } = useLocale(); const router = useRouter(); - + const [deleteDialogOpen, setDeleteDialogOpen] = useState(false); + const [deleteDialogTypeId, setDeleteDialogTypeId] = useState(0); const utils = trpc.useContext(); const mutation = trpc.useMutation("viewer.eventTypeOrder", { onError: async (err) => { @@ -182,11 +183,13 @@ export const EventTypeList = ({ group, groupIndex, readOnly, types }: EventTypeL onSuccess: async () => { await utils.invalidateQueries(["viewer.eventTypes"]); showToast(t("event_type_deleted_successfully"), "success"); + setDeleteDialogOpen(false); }, onError: (err) => { if (err instanceof HttpError) { const message = `${err.statusCode}: ${err.message}`; showToast(message, "error"); + setDeleteDialogOpen(false); } }, }); @@ -252,7 +255,7 @@ export const EventTypeList = ({ group, groupIndex, readOnly, types }: EventTypeL "flex justify-between space-x-2 rtl:space-x-reverse ", type.$disabled && "pointer-events-none cursor-not-allowed" )}> - + - + @@ -314,7 +316,7 @@ export const EventTypeList = ({ group, groupIndex, readOnly, types }: EventTypeL data-testid={"event-type-duplicate-" + type.id} StartIcon={DuplicateIcon} onClick={() => openModal(group, type)}> - {t("duplicate")} + {t("duplicate") as string} @@ -328,30 +330,17 @@ export const EventTypeList = ({ group, groupIndex, readOnly, types }: EventTypeL - - - - - { - e.preventDefault(); - deleteEventTypeHandler(type.id); - }}> - {t("delete_event_type_description")} - - + @@ -373,7 +362,7 @@ export const EventTypeList = ({ group, groupIndex, readOnly, types }: EventTypeL size="sm" StartIcon={ExternalLinkIcon} className="w-full rounded-none"> - {t("preview")} + {t("preview") as string} @@ -392,7 +381,7 @@ export const EventTypeList = ({ group, groupIndex, readOnly, types }: EventTypeL ); showToast(t("link_copied"), "success"); }}> - {t("copy_link")} + {t("copy_link") as string} {isNativeShare ? ( @@ -414,7 +403,7 @@ export const EventTypeList = ({ group, groupIndex, readOnly, types }: EventTypeL .then(() => showToast(t("link_shared"), "success")) .catch(() => showToast(t("failed"), "error")); }}> - {t("share")} + {t("share") as string} ) : null} @@ -426,8 +415,7 @@ export const EventTypeList = ({ group, groupIndex, readOnly, types }: EventTypeL color="minimal" className="w-full rounded-none" StartIcon={PencilIcon}> - {" "} - {t("edit")} + {t("edit") as string} @@ -439,35 +427,22 @@ export const EventTypeList = ({ group, groupIndex, readOnly, types }: EventTypeL data-testid={"event-type-duplicate-" + type.id} StartIcon={DuplicateIcon} onClick={() => openModal(group, type)}> - {t("duplicate")} + {t("duplicate") as string} - - - - - { - e.preventDefault(); - deleteEventTypeHandler(type.id); - }}> - {t("delete_event_type_description")} - - + @@ -476,6 +451,20 @@ export const EventTypeList = ({ group, groupIndex, readOnly, types }: EventTypeL ))} + + { + e.preventDefault(); + deleteEventTypeHandler(deleteDialogTypeId); + }}> + {t("delete_event_type_description") as string} + + ); }; @@ -556,8 +545,8 @@ const EventTypesPage = () => { } customLoader={}>