import { Button } from '@gitroom/react/form/button';
import { useFetch } from '@gitroom/helpers/utils/custom.fetch';
import useSWR from 'swr';
import React, { useCallback, useMemo } from 'react';
import { useUser } from '@gitroom/frontend/components/layout/user.context';
import { capitalize } from 'lodash';
import { useModals } from '@gitroom/frontend/components/layout/new-modal';
import { TopTitle } from '@gitroom/frontend/components/launches/helpers/top.title.component';
import { Input } from '@gitroom/react/form/input';
import { useForm, FormProvider, useWatch } from 'react-hook-form';
import { Select } from '@gitroom/react/form/select';
import { Checkbox } from '@gitroom/react/form/checkbox';
import { classValidatorResolver } from '@hookform/resolvers/class-validator';
import { AddTeamMemberDto } from '@gitroom/nestjs-libraries/dtos/settings/add.team.member.dto';
import { useToaster } from '@gitroom/react/toaster/toaster';
import { deleteDialog } from '@gitroom/react/helpers/delete.dialog';
import copy from 'copy-to-clipboard';
import { useT } from '@gitroom/react/translation/get.transation.service.client';
const roles = [
{
name: 'User',
value: 'USER',
},
{
name: 'Admin',
value: 'ADMIN',
},
];
export const AddMember = () => {
const modals = useModals();
const fetch = useFetch();
const toast = useToaster();
const resolver = useMemo(() => {
return classValidatorResolver(AddTeamMemberDto);
}, []);
const form = useForm({
values: {
email: '',
role: '',
sendEmail: true,
},
resolver,
mode: 'onChange',
});
const sendEmail = useWatch({
control: form.control,
name: 'sendEmail',
});
const submit = useCallback(
async (values: { email: string; role: string; sendEmail: boolean }) => {
const { url } = await (
await fetch('/settings/team', {
method: 'POST',
body: JSON.stringify(values),
})
).json();
if (values.sendEmail) {
modals.closeAll();
toast.show('Invitation link sent');
return;
}
copy(url);
modals.closeAll();
toast.show('Link copied to clipboard');
},
[]
);
const t = useT();
return (