import { Info, Subtitle } from 'app/atoms/text'; import Switch from 'app/components/inputs/switch'; import Languages from 'app/features/global/services/languages-service'; import { ToasterService } from 'app/features/global/services/toaster-service'; import { useInvitationUsers } from 'app/features/invitation/hooks/use-invitation-users'; import { useCurrentUser } from 'app/features/users/hooks/use-current-user'; import workspaceApiClient from 'app/features/workspaces/api/workspace-api-client'; import { useCurrentWorkspace } from 'app/features/workspaces/hooks/use-workspaces'; import React, { useState } from 'react'; export default (): React.ReactElement => { const { user } = useCurrentUser(); const { members_limit_reached } = useInvitationUsers(); const { workspace } = useCurrentWorkspace(); const [allow, setAllow] = useState(!!workspace?.preferences?.invite_domain); const currentUserDomain = user?.email.split('@').pop(); const handleChange = async (value: boolean): Promise => { if (value) { try { await workspaceApiClient.setInvitationDomain( workspace?.company_id as string, workspace?.id as string, currentUserDomain as string, ); setAllow(true); ToasterService.success('Invitation domain updated'); } catch (error) { ToasterService.error('Failed to set invitation domain'); } } }; return !members_limit_reached ? ( <> Automatically invite my business If this is enabled, anyone creating a Tdrive account with your business email will automatically be added to this company and this workspace.
{Languages.t( 'components.invitation.allow_anyone_by_email.text', [workspace?.preferences?.invite_domain || currentUserDomain], `Let anyone with @${ workspace?.preferences?.invite_domain || currentUserDomain } email join this workspace`, )}
) : ( <> ); };