mirror of
https://github.com/jambonz/jambonz-webapp.git
synced 2026-10-21 19:04:22 +00:00
22 lines
472 B
TypeScript
22 lines
472 B
TypeScript
import { useEffect } from "react";
|
|
import { useNavigate } from "react-router-dom";
|
|
|
|
import { toastError } from "src/store";
|
|
|
|
import type { IMessage } from "src/store/types";
|
|
|
|
export const useRedirect = <Type>(
|
|
collection: Type[] | undefined,
|
|
redirect: string,
|
|
message: IMessage
|
|
) => {
|
|
const navigate = useNavigate();
|
|
|
|
useEffect(() => {
|
|
if (collection && !collection.length) {
|
|
toastError(message);
|
|
navigate(redirect);
|
|
}
|
|
}, [collection]);
|
|
};
|