Skip to content

Commit

Permalink
added direct invite email post request
Browse files Browse the repository at this point in the history
  • Loading branch information
desperado1802 committed Dec 3, 2023
1 parent edea71d commit a23264d
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 7 deletions.
16 changes: 13 additions & 3 deletions apps/web/app/hooks/features/useTeamInvitations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,22 @@ export function useTeamInvitations() {

const inviteUser = useCallback(
(email: string, name: string) => {
return inviteQueryCall({ email, name }, user?.tenantId as string).then((res) => {
setTeamInvitations(res.data?.items || []);
return inviteQueryCall(
{
email,
name,
organizationId: user?.employee.organizationId as string,
teamId: activeTeamId as string
},
user?.tenantId as string
).then((res) => {
console.log('invited!!!!:', res);

setTeamInvitations((prev) => [...prev, ...(res.data?.items || [])]);
return res;
});
},
[inviteQueryCall, setTeamInvitations, user?.tenantId]
[inviteQueryCall, setTeamInvitations, user?.tenantId, activeTeamId, user?.employee.organizationId]
);

useEffect(() => {
Expand Down
54 changes: 51 additions & 3 deletions apps/web/app/services/client/api/invite.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,63 @@
import { PaginationResponse } from '@app/interfaces/IDataResponse';
import { IInvitation, IInviteRequest, MyInvitationActionEnum, CreateResponse } from '@app/interfaces';
import {
IInvitation,
// IInviteRequest,
MyInvitationActionEnum,
CreateResponse,
IInviteCreate
} from '@app/interfaces';
import { INVITE_CALLBACK_URL } from '@app/constants';
import api, { get, post } from '../axios';
// import { getEmployeeRoleRequest } from '@app/services/server/requests';
// import { getCookie } from 'cookies-next';

// export function inviteByEmailsAPI(data: IInviteRequest) {
// return api.post<PaginationResponse<IInvitation>>('/invite/emails', data);
// }

export async function inviteByEmailsAPI(data: IInviteRequest, tenantId: string) {
interface IIInviteRequest {
email: string;
name: string;
teamId: string;
organizationId: string;
}

export async function inviteByEmailsAPI(data: IIInviteRequest, tenantId: string) {
const endpoint = '/invite/emails';

return await post(endpoint, data, false, { tenantId });
// const authToken = getCookie('auth-token')?.toString();

const date = new Date();
date.setDate(date.getDate() - 1);

// console.log('authToken:', authToken);
// console.log('tenantId:', tenantId);

// const { data: employeeRole } = await getEmployeeRoleRequest({
// tenantId,
// role: 'EMPLOYEE',
// bearer_token: authToken as string
// });

const dataToInviteUser: IInviteCreate = {
emailIds: [data.email],
projectIds: [],
departmentIds: [],
organizationContactIds: [],
teamIds: [data.teamId],
roleId: 'b1d702d9-9380-4cda-a442-0e7d1ca7480e' || '',
invitationExpirationPeriod: 'Never',
inviteType: 'TEAM',
appliedDate: null,
fullName: data.name,
callbackUrl: INVITE_CALLBACK_URL,
organizationId: data.organizationId,
startedWorkOn: date.toISOString()
};

const fetchData = await post(endpoint, dataToInviteUser, true, { tenantId });

return process.env.NEXT_PUBLIC_GAUZY_API_SERVER_URL ? fetchData.data : fetchData;
}

export async function getTeamInvitationsAPI(tenantId: string, organizationId: string, role: string, teamId: string) {
Expand Down
1 change: 0 additions & 1 deletion apps/web/app/services/client/axios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ function post(
headers: {
...(extras?.tenantId ? { 'tenant-id': extras?.tenantId } : {})
}
// eslint-disable-next-line
})
: api.post(endpoint, data);
}
Expand Down
2 changes: 2 additions & 0 deletions apps/web/app/services/server/requests/roles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export function getEmployeeRoleRequest({
role: 'EMPLOYEE';
tenantId: string;
}) {
console.log('authToken:', bearer_token);
console.log('tenantId:', tenantId);
return serverFetch<IRole>({
path: `/roles/options?name=${role}`,
method: 'GET',
Expand Down

0 comments on commit a23264d

Please sign in to comment.