import { useOrg } from '@components/Contexts/OrgContext' import { getAPIUrl, getUriWithOrg } from '@services/config/config' import { createInviteCode, createInviteCodeWithUserGroup } from '@services/organizations/invites' import { swrFetcher } from '@services/utils/ts/requests' import { Ticket } from 'lucide-react' import { useLHSession } from '@components/Contexts/LHSessionContext' import React, { useEffect } from 'react' import toast from 'react-hot-toast' import useSWR, { mutate } from 'swr' import Link from 'next/link' type OrgInviteCodeGenerateProps = { setInvitesModal: any } function OrgInviteCodeGenerate(props: OrgInviteCodeGenerateProps) { const org = useOrg() as any const session = useLHSession() as any const access_token = session?.data?.tokens?.access_token; const [usergroup_id, setUsergroup_id] = React.useState(0); const { data: usergroups } = useSWR( org ? `${getAPIUrl()}usergroups/org/${org.id}` : null, (url) => swrFetcher(url, access_token) ) async function createInviteWithUserGroup() { let res = await createInviteCodeWithUserGroup(org.id, usergroup_id, session.data?.tokens?.access_token) if (res.status == 200) { mutate(`${getAPIUrl()}orgs/${org.id}/invites`) props.setInvitesModal(false) } else { toast.error('Error ' + res.status + ': ' + res.data.detail) } } async function createInvite() { let res = await createInviteCode(org.id, session.data?.tokens?.access_token) if (res.status == 200) { mutate(`${getAPIUrl()}orgs/${org.id}/invites`) props.setInvitesModal(false) } else { toast.error('Error ' + res.status + ': ' + res.data.detail) } } useEffect(() => { if (usergroups && usergroups.length > 0) { setUsergroup_id(usergroups[0].id) } } , [usergroups]) return (

Invite Code linked to a UserGroup

On Signup, Users will be automatically linked to a UserGroup of your choice

{usergroups?.length >= 1 &&
} {usergroups?.length == 0 &&
No UserGroups available Create a UserGroup
}

Normal Invite Code

On Signup, User will not be linked to any UserGroup

) } export default OrgInviteCodeGenerate