From de39e35e0aa73876212f36884e04b65c34d54ee5 Mon Sep 17 00:00:00 2001 From: zerosoul Date: Wed, 30 Mar 2022 23:17:04 +0800 Subject: [PATCH] feat: invite link with SMTP check --- src/common/component/InviteLink.js | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/common/component/InviteLink.js b/src/common/component/InviteLink.js index c41381da..5d6c2468 100644 --- a/src/common/component/InviteLink.js +++ b/src/common/component/InviteLink.js @@ -1,7 +1,10 @@ import { useEffect } from "react"; import styled from "styled-components"; import { useSelector } from "react-redux"; -import { useLazyCreateInviteLinkQuery } from "../../app/services/server"; +import { + useLazyCreateInviteLinkQuery, + useGetSMTPConfigQuery, +} from "../../app/services/server"; import Button from "./styled/Button"; import useCopy from "../hook/useCopy"; const StyledWrapper = styled.div` @@ -47,6 +50,10 @@ const StyledWrapper = styled.div` } `; export default function InviteLink() { + const { + data: config, + isSuccess: configQuerySuccess, + } = useGetSMTPConfigQuery(); const [copid, copy] = useCopy(); const { inviteLink: { link }, @@ -66,17 +73,23 @@ export default function InviteLink() { const handleNewLink = () => { createLink(); }; - if (!loginUser || !loginUser.is_admin) return null; + if (!loginUser || !loginUser.is_admin || !configQuerySuccess) return null; + let finalLink = null; + if (link) { + const tmpURL = new URL(link); + tmpURL.searchParams.set("code", config.enabled); + finalLink = tmpURL.href; + } return ( Share this link to invite people to this server.
- - {link} + + {finalLink} -