From 73df08fcc7cf3e7ea565f224a389976310c6eb05 Mon Sep 17 00:00:00 2001 From: Tristan Yang Date: Fri, 9 Dec 2022 20:49:40 +0800 Subject: [PATCH] fix: invite by email in modal --- .../component/InviteModal/InviteByEmail.tsx | 46 ++++++++++++++----- 1 file changed, 35 insertions(+), 11 deletions(-) diff --git a/src/common/component/InviteModal/InviteByEmail.tsx b/src/common/component/InviteModal/InviteByEmail.tsx index a89dcbc0..1c5db215 100644 --- a/src/common/component/InviteModal/InviteByEmail.tsx +++ b/src/common/component/InviteModal/InviteByEmail.tsx @@ -1,7 +1,8 @@ -import { useEffect, useState, ChangeEvent, FC } from "react"; +import { useEffect, useState, ChangeEvent, FC, useRef } from "react"; import toast from "react-hot-toast"; import { useTranslation } from "react-i18next"; import styled from "styled-components"; +import { useSendLoginMagicLinkMutation } from "../../../app/services/auth"; import useInviteLink from "../../hook/useInviteLink"; import Button from "../styled/Button"; import Input from "../styled/Input"; @@ -74,7 +75,10 @@ interface Props { const InviteByEmail: FC = ({ cid }) => { const { t } = useTranslation("chat"); + const { t: ct } = useTranslation(); const [email, setEmail] = useState(""); + const formRef = useRef(null); + const [sendMagicLinkByEmail, { isSuccess, isLoading }] = useSendLoginMagicLinkMutation(); const { enableSMTP, linkCopied, link, copyLink, generateNewLink, generating } = useInviteLink(cid); useEffect(() => { @@ -82,25 +86,45 @@ const InviteByEmail: FC = ({ cid }) => { toast.success("Invite Link Copied!"); } }, [linkCopied]); + useEffect(() => { + if (isSuccess) { + + toast.success("Email Sent!"); + } + }, [isSuccess]); const handleEmail = (evt: ChangeEvent) => { setEmail(evt.target.value); }; + const handleSendEmail = () => { + if (formRef && formRef.current) { + const formEle = formRef.current; + if (!formEle.checkValidity()) { + formEle.reportValidity(); + } else { + sendMagicLinkByEmail(email); + } + } + }; return (
- -
@@ -109,7 +133,7 @@ const InviteByEmail: FC = ({ cid }) => {