fix: prevent duplicate calendar account linking (#13310)

* fix: prevent signing up multiple times from same account

* revert: lark calendar changes

* credential clean up if duplicate

* fix code duplication and check before credential creation

* feat: useRouterQuery allow unset queryParam

* feat: showToast on account duplication attempt

* Small tweak to copy

* Updated other calendars not to use checkDuplicateCalendar

* Add account already linked to apps/installed/calendar

---------

Co-authored-by: Keith Williams <[email protected]>
Co-authored-by: Alex van Andel <[email protected]>
Co-authored-by: Udit Takkar <[email protected]>
This commit is contained in:
authored and GitHub committed 2024-02-08 10:52:32 +00:00
1 parent 97dcb2a2a9
commit 3348e7be2f
8 files changed
+142 -63

No files matched your search

+24 -24
View File
@@ -1,4 +1,5 @@
import classNames from "classnames";
import type { ToastOptions, Toast } from "react-hot-toast";
import toast from "react-hot-toast";
import { Check, Info } from "../icon";
@@ -76,34 +77,33 @@ export const DefaultToast = ({ message, toastVisible, onClose, toastId }: IToast
const TOAST_VISIBLE_DURATION = 6000;
type ToastVariants = "success" | "warning" | "error";
export function showToast(
message: string,
variant: "success" | "warning" | "error",
duration = TOAST_VISIBLE_DURATION
variant: ToastVariants,
// Options or duration (duration for backwards compatibility reasons)
options: number | ToastOptions = TOAST_VISIBLE_DURATION
) {
//
const _options: ToastOptions = typeof options === "number" ? { duration: options } : options;
if (!_options.duration) _options.duration = TOAST_VISIBLE_DURATION;
const onClose = (toastId: string) => {
toast.remove(toastId);
};
switch (variant) {
case "success":
return toast.custom(
(t) => <SuccessToast message={message} toastVisible={t.visible} onClose={onClose} toastId={t.id} />,
{ duration }
);
case "error":
return toast.custom(
(t) => <ErrorToast message={message} toastVisible={t.visible} onClose={onClose} toastId={t.id} />,
{ duration }
);
case "warning":
return toast.custom(
(t) => <WarningToast message={message} toastVisible={t.visible} onClose={onClose} toastId={t.id} />,
{ duration }
);
default:
return toast.custom(
(t) => <DefaultToast message={message} toastVisible={t.visible} onClose={onClose} toastId={t.id} />,
{ duration }
);
}
const toastElements: { [x in ToastVariants]: (t: Toast) => JSX.Element } = {
success: (t) => (
<SuccessToast message={message} toastVisible={t.visible} onClose={onClose} toastId={t.id} />
),
error: (t) => <ErrorToast message={message} toastVisible={t.visible} onClose={onClose} toastId={t.id} />,
warning: (t) => (
<WarningToast message={message} toastVisible={t.visible} onClose={onClose} toastId={t.id} />
),
};
return toast.custom(
toastElements[variant] ||
((t) => <DefaultToast message={message} toastVisible={t.visible} onClose={onClose} toastId={t.id} />),
_options
);
}