Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | 72x 1059x 1059x 1059x 1059x 72x 89x 89x 89x 89x 89x 87x 89x | import { showMessage } from "@common/Toast";
import { customInstance } from "@services/api";
import { MemberData } from "@customTypes/team.member";
import { useState } from "react";
import { useGetCurrentMerchantId } from "@hooks/common";
import { useMutation, useQueryClient } from "react-query";
import { MERCHANT_SIDE_PANEL_PREVIEW_API_KEYS } from "@features/Merchants/MerchantSidePanel/constants";
const useResendInvite = () => {
const queryClient = useQueryClient();
const { mutateAsync } = useMutation((data: any) => {
return customInstance({
url: `/accounts/${data?.merchantId}/invites/${data?.inviteId}/resend`,
method: "POST",
});
});
const sendInvite = async (
merchantId: number,
inviteId: number,
isMobile?: boolean,
) => {
try {
await mutateAsync({ merchantId, inviteId });
queryClient.invalidateQueries([
MERCHANT_SIDE_PANEL_PREVIEW_API_KEYS.GET,
merchantId,
]);
showMessage("Invitation", "", !isMobile, "Invitation resent", 5000, {
style: {
fontFamily: "inherit",
},
});
} catch (err: any) {
showMessage("Error", "", !isMobile, err?.response?.data?.message);
}
};
return { sendInvite };
};
export const useSendInvitationAction = () => {
const [resentInvitationsIDs, setResentInvitationsIDs] = useState<number[]>(
[],
);
const { sendInvite } = useResendInvite();
const { merchantId } = useGetCurrentMerchantId();
const handleResendInvitation = (row?: MemberData, isMobile = false) => {
if (!row || !row.invite?.id) return;
sendInvite(merchantId, row.invite.id, isMobile);
setResentInvitationsIDs((prev) => [...prev, row.user.accID]);
};
const checkIsInvitationSent = (selectedRow?: MemberData) =>
resentInvitationsIDs.some((id) => id === selectedRow?.user.accID);
return {
resentInvitationsIDs,
handleResendInvitation,
checkIsInvitationSent,
};
};
export default useResendInvite;
|