fix: invite by email in modal
This commit is contained in:
@@ -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 toast from "react-hot-toast";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import styled from "styled-components";
|
import styled from "styled-components";
|
||||||
|
import { useSendLoginMagicLinkMutation } from "../../../app/services/auth";
|
||||||
import useInviteLink from "../../hook/useInviteLink";
|
import useInviteLink from "../../hook/useInviteLink";
|
||||||
import Button from "../styled/Button";
|
import Button from "../styled/Button";
|
||||||
import Input from "../styled/Input";
|
import Input from "../styled/Input";
|
||||||
@@ -74,7 +75,10 @@ interface Props {
|
|||||||
|
|
||||||
const InviteByEmail: FC<Props> = ({ cid }) => {
|
const InviteByEmail: FC<Props> = ({ cid }) => {
|
||||||
const { t } = useTranslation("chat");
|
const { t } = useTranslation("chat");
|
||||||
|
const { t: ct } = useTranslation();
|
||||||
const [email, setEmail] = useState("");
|
const [email, setEmail] = useState("");
|
||||||
|
const formRef = useRef<HTMLFormElement | null>(null);
|
||||||
|
const [sendMagicLinkByEmail, { isSuccess, isLoading }] = useSendLoginMagicLinkMutation();
|
||||||
const { enableSMTP, linkCopied, link, copyLink, generateNewLink, generating } =
|
const { enableSMTP, linkCopied, link, copyLink, generateNewLink, generating } =
|
||||||
useInviteLink(cid);
|
useInviteLink(cid);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -82,25 +86,45 @@ const InviteByEmail: FC<Props> = ({ cid }) => {
|
|||||||
toast.success("Invite Link Copied!");
|
toast.success("Invite Link Copied!");
|
||||||
}
|
}
|
||||||
}, [linkCopied]);
|
}, [linkCopied]);
|
||||||
|
useEffect(() => {
|
||||||
|
if (isSuccess) {
|
||||||
|
|
||||||
|
toast.success("Email Sent!");
|
||||||
|
}
|
||||||
|
}, [isSuccess]);
|
||||||
|
|
||||||
const handleEmail = (evt: ChangeEvent<HTMLInputElement>) => {
|
const handleEmail = (evt: ChangeEvent<HTMLInputElement>) => {
|
||||||
setEmail(evt.target.value);
|
setEmail(evt.target.value);
|
||||||
};
|
};
|
||||||
|
const handleSendEmail = () => {
|
||||||
|
if (formRef && formRef.current) {
|
||||||
|
const formEle = formRef.current;
|
||||||
|
if (!formEle.checkValidity()) {
|
||||||
|
formEle.reportValidity();
|
||||||
|
} else {
|
||||||
|
sendMagicLinkByEmail(email);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Styled>
|
<Styled>
|
||||||
<div className="invite">
|
<div className="invite">
|
||||||
<label htmlFor="">{t("invite_by_email")}</label>
|
<label htmlFor="">{t("invite_by_email")}</label>
|
||||||
<div className="input">
|
<div className="input">
|
||||||
|
<form ref={formRef} action="/" className="w-full">
|
||||||
<Input
|
<Input
|
||||||
|
required
|
||||||
value={email}
|
value={email}
|
||||||
onChange={handleEmail}
|
onChange={handleEmail}
|
||||||
disabled={!enableSMTP}
|
disabled={!enableSMTP}
|
||||||
type="email"
|
type="email"
|
||||||
|
name="email"
|
||||||
placeholder={enableSMTP ? "Enter Email" : t("enable_smtp")}
|
placeholder={enableSMTP ? "Enter Email" : t("enable_smtp")}
|
||||||
/>
|
/>
|
||||||
<Button disabled={!enableSMTP || !email} className="send">
|
</form>
|
||||||
{t("action.send", { ns: "common" })}
|
<Button disabled={!enableSMTP || !email || isLoading} className="send" onClick={handleSendEmail}>
|
||||||
|
{ct("action.send")}
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -109,7 +133,7 @@ const InviteByEmail: FC<Props> = ({ cid }) => {
|
|||||||
<div className="input">
|
<div className="input">
|
||||||
<Input readOnly className="invite" placeholder="Generating" value={link} />
|
<Input readOnly className="invite" placeholder="Generating" value={link} />
|
||||||
<button className="copy" onClick={copyLink}>
|
<button className="copy" onClick={copyLink}>
|
||||||
{t("action.copy", { ns: "common" })}
|
{ct("action.copy")}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user