Files
jambonz-webapp/src/utils/use-redirect.ts
T
Hoan Luu Huu e65d9b9db6 some S3 compatible storage systems have a region parameter (#524)
* some S3 compatible storage systems have a region parameter

* wip

* wip

* replace current toastMethod by new toastProvider

* wip

* fix failing testcase

* wip
2025-05-28 10:03:39 -04:00

22 lines
533 B
TypeScript

import { useEffect } from "react";
import { useNavigate } from "react-router-dom";
import { useToast } from "src/components/toast/toast-provider";
import type { IMessage } from "src/store/types";
export const useRedirect = <Type>(
collection: Type[] | undefined,
redirect: string,
message: IMessage,
) => {
const navigate = useNavigate();
const { toastError } = useToast();
useEffect(() => {
if (collection && !collection.length) {
toastError(message);
navigate(redirect);
}
}, [collection]);
};