From 282aa4e409cb291a9ccef9cc12b4f12aac897479 Mon Sep 17 00:00:00 2001 From: Robinson-Taiwo Date: Sat, 17 Aug 2024 09:07:50 +0100 Subject: [PATCH 1/3] Fix: Fix backend invite link generation. --- src/actions/inviteMembers.ts | 7 ++++++- .../common/modals/invite-member/index.tsx | 17 ++++++++++------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/actions/inviteMembers.ts b/src/actions/inviteMembers.ts index db484c5d2..732d40b31 100644 --- a/src/actions/inviteMembers.ts +++ b/src/actions/inviteMembers.ts @@ -151,7 +151,12 @@ export const generateInviteLink = async ( ); // Extract the invite link from the nested data object - const inviteLink = response.data.data.invite_link; + let inviteLink = response.data.data.invite_link; + + // Ensure the link has a slash between the domain and the path + if (!inviteLink.includes("/invite")) { + inviteLink = inviteLink.replace("techinvite", "tech/invite"); + } return { data: inviteLink, diff --git a/src/components/common/modals/invite-member/index.tsx b/src/components/common/modals/invite-member/index.tsx index f79ca57b9..14cc357a0 100644 --- a/src/components/common/modals/invite-member/index.tsx +++ b/src/components/common/modals/invite-member/index.tsx @@ -70,6 +70,10 @@ const InviteMemberModal: React.FC = ({ show, onClose }) => { } }; + // Clear error after a timeout + const clearError = () => setTimeout(() => setError(""), 3000); + + // Function to handle invite submission via email const handleSubmit = async () => { setError(""); @@ -87,8 +91,8 @@ const InviteMemberModal: React.FC = ({ show, onClose }) => { } }; - const clearError = () => setTimeout(() => setError(""), 3000); - const handleInviteWithLink = async () => { + // Function to generate the invite link + const generateAndCopyInviteLink = async () => { if (!organization) { setError("Please select an organization first."); clearError(); @@ -109,11 +113,10 @@ const InviteMemberModal: React.FC = ({ show, onClose }) => { setError(inviteLinkError); clearError(); } else { - setInviteLink(inviteLinkData); // Correctly store the invite link + setInviteLink(inviteLinkData); // Store the invite link setLinkGenerated(true); try { - // Ensure the document is focused before attempting to write to the clipboard if (document.hasFocus()) { await navigator.clipboard.writeText(inviteLinkData); toast({ @@ -183,7 +186,7 @@ const InviteMemberModal: React.FC = ({ show, onClose }) => { Invite with link @@ -195,8 +198,8 @@ const InviteMemberModal: React.FC = ({ show, onClose }) => { {linkGenerated && ( -
- Invite link: {inviteLink} +
+ {inviteLink}
)} From ed14b87ceb34a32a49863f0b952f9e8ac41f4477 Mon Sep 17 00:00:00 2001 From: Robinson-Taiwo Date: Sat, 17 Aug 2024 13:46:42 +0100 Subject: [PATCH 2/3] Fix: Fixed backend implementation --- src/actions/inviteMembers.ts | 10 +++------- src/app/invite/index.tsx | 7 +++++++ src/components/common/modals/invite-member/index.tsx | 11 ++--------- 3 files changed, 12 insertions(+), 16 deletions(-) create mode 100644 src/app/invite/index.tsx diff --git a/src/actions/inviteMembers.ts b/src/actions/inviteMembers.ts index 732d40b31..fb465c974 100644 --- a/src/actions/inviteMembers.ts +++ b/src/actions/inviteMembers.ts @@ -99,6 +99,7 @@ export const acceptInvite = async (inviteLink: string) => { if (!token) { return { error: "Invalid invite link. No token found.", + status: 400, // Bad Request }; } @@ -115,7 +116,6 @@ export const acceptInvite = async (inviteLink: string) => { }, ); - // Handle the response as needed return { data: response.data, status: response.status, @@ -128,14 +128,11 @@ export const acceptInvite = async (inviteLink: string) => { } : { error: "An unexpected error occurred.", + status: 500, // Internal Server Error }; } }; - -export const generateInviteLink = async ( - org_id: string, - invite_token: string, -) => { +export const generateInviteLink = async (org_id: string) => { const apiUrl = await getApiUrl(); const session = await auth(); @@ -143,7 +140,6 @@ export const generateInviteLink = async ( const response = await axios.get( `${apiUrl}/api/v1/organisations/${org_id}/invites`, { - params: { invite_token }, headers: { Authorization: `Bearer ${session?.access_token}`, }, diff --git a/src/app/invite/index.tsx b/src/app/invite/index.tsx new file mode 100644 index 000000000..a85b3175c --- /dev/null +++ b/src/app/invite/index.tsx @@ -0,0 +1,7 @@ +"use client"; + +const InvitePage = () => { + return
Processing your invite...
; +}; + +export default InvitePage; diff --git a/src/components/common/modals/invite-member/index.tsx b/src/components/common/modals/invite-member/index.tsx index 14cc357a0..ce0f294af 100644 --- a/src/components/common/modals/invite-member/index.tsx +++ b/src/components/common/modals/invite-member/index.tsx @@ -99,15 +99,8 @@ const InviteMemberModal: React.FC = ({ show, onClose }) => { return; } - const inviteResponse = await inviteMembers(emails, organization); - if (inviteResponse?.error) { - setError(inviteResponse.error); - clearError(); - return; - } - const { data: inviteLinkData, error: inviteLinkError } = - await generateInviteLink(organization, inviteResponse.data.invite_token); + await generateInviteLink(organization); if (inviteLinkError) { setError(inviteLinkError); @@ -198,7 +191,7 @@ const InviteMemberModal: React.FC = ({ show, onClose }) => {
{linkGenerated && ( -
+
{inviteLink}
)} From a09942b65308a56999c72df4ec3c869f13cb532e Mon Sep 17 00:00:00 2001 From: Robinson-Taiwo Date: Sat, 17 Aug 2024 15:08:50 +0100 Subject: [PATCH 3/3] Chore: clean up unnecessary created route --- src/app/invite/index.tsx | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 src/app/invite/index.tsx diff --git a/src/app/invite/index.tsx b/src/app/invite/index.tsx deleted file mode 100644 index a85b3175c..000000000 --- a/src/app/invite/index.tsx +++ /dev/null @@ -1,7 +0,0 @@ -"use client"; - -const InvitePage = () => { - return
Processing your invite...
; -}; - -export default InvitePage;