feat: updated api for profile, organization & invitations

This commit is contained in:
Nishchit14
2023-07-27 13:19:20 +05:30
parent d02d108e97
commit 16d41456ff
9 changed files with 5334 additions and 5251 deletions

View File

@@ -50,7 +50,7 @@
},
"dependencies": {
"@firecamp/agent-manager": "workspace:*",
"@firecamp/cloud-apis": "^0.2.8",
"@firecamp/cloud-apis": "0.2.9",
"@firecamp/cookie-manager": "^0.0.0",
"@firecamp/graphql": "workspace:*",
"@firecamp/rest": "workspace:*",

View File

@@ -135,6 +135,7 @@ const GlobalCreateDD = ({}) => {
<Button
leftIcon={<AlignCenter size={20}/>}
rightIcon={<VscTriangleDown size={12} className={classnames({'transform rotate-180': isOpen})}/>}
animate={false}
transparent
primary
compact

View File

@@ -1,23 +1,34 @@
import { FC, useState } from 'react';
import { FC, useEffect, useState } from 'react';
import { _array } from '@firecamp/utils';
import { Container, Drawer, IModal } from '@firecamp/ui';
import InvitationCard from './InvitationCard';
import platformContext from '../../../services/platform-context';
import { IInvite } from './InvitationCard.interface';
// TODO: remove dummy data
// const cinvite = {
// inviterName: 'Nishchit14',
// orgName: 'Firecamp',
// workspaceName: 'testing',
// role: 2,
// token: 'firecamp-token',
// };
import { Rest } from '@firecamp/cloud-apis';
const AllInvitation: FC<IModal> = ({ opened, onClose }) => {
const [list, updateList] = useState<Array<IInvite> | []>([]);
const [inviteId, updateInviteId] = useState('');
const [isRequesting, setIsRequesting] = useState(false);
const [isFetching, setIsFetching] = useState(false);
// todo add invitation listing logic
useEffect(() => {
setIsFetching(true);
Rest.invitation
.getMyPendingInvitations()
.then((res) => res.data)
.then((list) => {
updateList(list);
})
.finally(() => setIsFetching(false));
}, []);
const switchToWrs = async (wrs: any) => {
await platformContext.app.switchWorkspace(wrs);
platformContext.app.modals.close();
};
const _handleInvitation = async (invite: IInvite) => {
if (isRequesting) return;
@@ -25,39 +36,47 @@ const AllInvitation: FC<IModal> = ({ opened, onClose }) => {
setIsRequesting(true);
updateInviteId(invite.token);
//TODO: update invitation api
Rest.invitation
.accept(invite.token)
.then((res) => res.data)
.then(({ error, message }) => {
if (!error) {
platformContext.app.notify.success(
'You have successfully joined the invitation',
{ label: { success: 'Updated Invitation' } }
);
// Rest.user
// .updateInvitation(invite.token)
// .then(() => {
// platformContext.app.notify.success(
// 'You have successfully joined the invitation'
// );
// TODO: check for workspace details for switchToWrs(workspace)..
platformContext.window.confirm({
message:
'Congratulations on joining the invitation! Are you interested in switching workspaces and start collaboration?',
labels: { confirm: 'Yes, switch workspace.' },
onConfirm: () => {
platformContext.app.modals.openSwitchWorkspace();
},
onCancel: () => {
platformContext.window.confirm({
message:
'Congratulations on joining the invitation! Are you interested in switching workspaces and start collaboration?',
labels: { confirm: 'Yes, switch workspace.' },
onConfirm: () => switchToWrs(invite),
onCancel: () => {
setIsRequesting(false);
updateInviteId('');
},
});
let Index = list.findIndex((i) => i.token === invite.token);
updateList((list) => [
...list.slice(0, Index),
...list.slice(Index + 1),
]);
} else {
platformContext.app.notify.alert(message, {
label: { alert: 'Updated Invitation' },
});
}
})
.catch((e) => {
platformContext.app.notify.alert(e.response?.data.message || e.message);
})
.finally(() => {
setIsRequesting(false);
updateInviteId('');
},
});
let Index = list.findIndex((i) => i.token === invite.token);
updateList((list) => [...list.slice(0, Index), ...list.slice(Index + 1)]);
// })
// .catch((e) => {
// platformContext.app.notify.alert(e.response?.data.message || e.message);
// })
// .finally(() => {
// setIsRequesting(false);
// updateInviteId('');
// });
});
};
return (

View File

@@ -127,7 +127,7 @@ const OrgManagement: FC<IModal> = ({ opened = false, onClose = () => {} }) => {
case ETabTypes.Workspaces:
return <Workspaces workspaces={workspaces} isFetching={isFetching} />;
case ETabTypes.Members:
return <Members members={members} isFetching={isFetching} />;
return <Members members={members} updateMembers={updateMembers} isFetching={isFetching} organizationId={organization.__ref.id}/>;
case ETabTypes.Billing:
return <BillingTab />;
default:

View File

@@ -55,7 +55,12 @@ const RoleOptions = [
},
];
const Members = ({ members = [], isFetching = false }) => {
const Members = ({
organizationId = '',
members = [],
updateMembers,
isFetching = false,
}) => {
const tableApi = useRef<TTableApi>(null);
useEffect(() => {
@@ -80,21 +85,38 @@ const Members = ({ members = [], isFetching = false }) => {
confirm: 'Yes, change the role.',
},
onConfirm: () => {
//TODO: add role update api
Rest.organization
.changeMemberRole(organizationId, row.id, row.role.id)
.then((res) => res.data)
.then(({ error, message }) => {
if (!error) {
tableApi.current.setRow({ ...row, role: row.role.id });
// Rest.workspace
// .changeMemberRole(workspace.__ref.id, row.id, row.role.id)
// .then(() => {
tableApi.current.setRow({ ...row, role: row.role.id });
platformContext.app.notify.success(
"The member's role has been changed successfully."
);
// })
// .catch((e) => {
// platformContext.app.notify.alert(
// e.response?.data.message || e.message
// );
// });
// update the member listing after update
let Index = members.findIndex((m) => m.id == row.id);
updateMembers([
...members.slice(0, Index),
{ ...members[Index], role: row.role.id },
...members.slice(Index + 1),
]);
platformContext.app.notify.success(
"The member's role has been changed successfully.",
{
labels: { success: 'Role Updated' },
}
);
} else {
platformContext.app.notify.alert(message, {
labels: { alert: 'Role Updated' },
});
}
})
.catch((e) => {
platformContext.app.notify.alert(
e.response?.data.message || e.message
);
});
},
});
};

View File

@@ -15,7 +15,7 @@ const ChangePassword = () => {
const [confirmPassword, toggleConfirmPassword] = useState(false);
const form = useForm();
const { handleSubmit, errors, getValues } = form;
const { handleSubmit, errors, getValues, reset } = form;
const _onSubmit = async (payload: {
currentPassword: string;
@@ -24,32 +24,39 @@ const ChangePassword = () => {
if (isRequesting) return;
setFlagIsRequesting(true);
// TODO: make api call
// await Rest.auth
// .resetPassword({...payload})
// .then((res) => {
// if ([200, 201].includes(res?.status)) {
// platformContext.app.notify.success(res.data?.message, {
// labels: { success: 'Reset password' },
// });
// platformContext.app.modals.openSignIn();
// } else {
// platformContext.app.notify.alert(`Failed to reset password!`, {
// labels: { alert: 'Reset password' },
// });
// }
// })
// .catch((e) => {
// platformContext.app.notify.alert(
// e?.response?.data?.message || e.message,
// {
// labels: { alert: 'error!' },
// }
// );
// })
// .finally(() => {
// setFlagIsRequesting(false);
// });
await Rest.user
.changePassword({
currentPassword: payload.currentPassword,
newPassword: payload.newPassword,
})
.then((res) => res.data)
.then(({ error, message }) => {
if (!error) {
reset({ currentPassword: '', newPassword: '', confirmPassword: '' });
platformContext.app.notify.success(message, {
labels: { success: 'Change password' },
});
} else {
platformContext.app.notify.alert(
message ?? `Failed to change password!`,
{
labels: { alert: 'Change password' },
}
);
}
})
.catch((e) => {
platformContext.app.notify.alert(
e?.response?.data?.message || e.message,
{
labels: { alert: 'error!' },
}
);
})
.finally(() => {
setFlagIsRequesting(false);
});
};
const _onKeyDown = (e: any) => e.key === 'Enter' && handleSubmit(_onSubmit);

View File

@@ -11,48 +11,48 @@ import { useUserStore } from '../../../store/user';
*/
const UpdateProfile = () => {
const [isRequesting, setFlagIsRequesting] = useState(false);
const form = useForm();
let { handleSubmit, errors } = form;
const {user} = useUserStore(s => ({
user: s.user
}))
const { user } = useUserStore((s) => ({
user: s.user,
}));
const _onSubmit = async (payload: {
name: string;
}) => {
const _onSubmit = async (payload: { name: string }) => {
if (isRequesting) return;
let { name } = payload;
setFlagIsRequesting(true);
// TODO: make api call
// await Rest.auth
// .resetPassword({ token, new_password: password })
// .then((res) => {
// if ([200, 201].includes(res?.status)) {
// platformContext.app.notify.success(res.data?.message, {
// labels: { success: 'Reset password' },
// });
// platformContext.app.modals.openSignIn();
// } else {
// platformContext.app.notify.alert(`Failed to reset password!`, {
// labels: { alert: 'Reset password' },
// });
// }
// })
// .catch((e) => {
// platformContext.app.notify.alert(
// e?.response?.data?.message || e.message,
// {
// labels: { alert: 'error!' },
// }
// );
// })
// .finally(() => {
// setFlagIsRequesting(false);
// });
await Rest.user
.updateProfile({ name })
.then((res) => res.data)
.then(({ error, message }) => {
if (!error) {
platformContext.app.notify.success(
message ?? `Your profile details are updated`,
{
labels: { success: 'Update profile' },
}
);
} else {
platformContext.app.notify.alert(message, {
labels: { alert: 'Update profile' },
});
}
})
.catch((e) => {
platformContext.app.notify.alert(
e?.response?.data?.message || e.message,
{
labels: { alert: 'error!' },
}
);
})
.finally(() => {
setFlagIsRequesting(false);
});
};
const _onKeyDown = (e: any) => e.key === 'Enter' && handleSubmit(_onSubmit);

View File

@@ -112,6 +112,7 @@ const SIOVersionDropDown: FC<any> = ({
className={cx({ 'transform rotate-180': isDropDownOpen })}
/>
}
animate={false}
secondary
xs
/>

10301
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff