mirror of
https://github.com/LukeHagar/firecamp.git
synced 2025-12-07 20:37:45 +00:00
feat: updated api for profile, organization & invitations
This commit is contained in:
@@ -50,7 +50,7 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@firecamp/agent-manager": "workspace:*",
|
"@firecamp/agent-manager": "workspace:*",
|
||||||
"@firecamp/cloud-apis": "^0.2.8",
|
"@firecamp/cloud-apis": "0.2.9",
|
||||||
"@firecamp/cookie-manager": "^0.0.0",
|
"@firecamp/cookie-manager": "^0.0.0",
|
||||||
"@firecamp/graphql": "workspace:*",
|
"@firecamp/graphql": "workspace:*",
|
||||||
"@firecamp/rest": "workspace:*",
|
"@firecamp/rest": "workspace:*",
|
||||||
|
|||||||
@@ -135,6 +135,7 @@ const GlobalCreateDD = ({}) => {
|
|||||||
<Button
|
<Button
|
||||||
leftIcon={<AlignCenter size={20}/>}
|
leftIcon={<AlignCenter size={20}/>}
|
||||||
rightIcon={<VscTriangleDown size={12} className={classnames({'transform rotate-180': isOpen})}/>}
|
rightIcon={<VscTriangleDown size={12} className={classnames({'transform rotate-180': isOpen})}/>}
|
||||||
|
animate={false}
|
||||||
transparent
|
transparent
|
||||||
primary
|
primary
|
||||||
compact
|
compact
|
||||||
|
|||||||
@@ -1,23 +1,34 @@
|
|||||||
import { FC, useState } from 'react';
|
import { FC, useEffect, useState } from 'react';
|
||||||
import { _array } from '@firecamp/utils';
|
import { _array } from '@firecamp/utils';
|
||||||
import { Container, Drawer, IModal } from '@firecamp/ui';
|
import { Container, Drawer, IModal } from '@firecamp/ui';
|
||||||
import InvitationCard from './InvitationCard';
|
import InvitationCard from './InvitationCard';
|
||||||
import platformContext from '../../../services/platform-context';
|
import platformContext from '../../../services/platform-context';
|
||||||
import { IInvite } from './InvitationCard.interface';
|
import { IInvite } from './InvitationCard.interface';
|
||||||
|
import { Rest } from '@firecamp/cloud-apis';
|
||||||
// TODO: remove dummy data
|
|
||||||
// const cinvite = {
|
|
||||||
// inviterName: 'Nishchit14',
|
|
||||||
// orgName: 'Firecamp',
|
|
||||||
// workspaceName: 'testing',
|
|
||||||
// role: 2,
|
|
||||||
// token: 'firecamp-token',
|
|
||||||
// };
|
|
||||||
|
|
||||||
const AllInvitation: FC<IModal> = ({ opened, onClose }) => {
|
const AllInvitation: FC<IModal> = ({ opened, onClose }) => {
|
||||||
const [list, updateList] = useState<Array<IInvite> | []>([]);
|
const [list, updateList] = useState<Array<IInvite> | []>([]);
|
||||||
const [inviteId, updateInviteId] = useState('');
|
const [inviteId, updateInviteId] = useState('');
|
||||||
const [isRequesting, setIsRequesting] = useState(false);
|
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) => {
|
const _handleInvitation = async (invite: IInvite) => {
|
||||||
if (isRequesting) return;
|
if (isRequesting) return;
|
||||||
@@ -25,39 +36,47 @@ const AllInvitation: FC<IModal> = ({ opened, onClose }) => {
|
|||||||
setIsRequesting(true);
|
setIsRequesting(true);
|
||||||
updateInviteId(invite.token);
|
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
|
// TODO: check for workspace details for switchToWrs(workspace)..
|
||||||
// .updateInvitation(invite.token)
|
|
||||||
// .then(() => {
|
|
||||||
// platformContext.app.notify.success(
|
|
||||||
// 'You have successfully joined the invitation'
|
|
||||||
// );
|
|
||||||
|
|
||||||
platformContext.window.confirm({
|
platformContext.window.confirm({
|
||||||
message:
|
message:
|
||||||
'Congratulations on joining the invitation! Are you interested in switching workspaces and start collaboration?',
|
'Congratulations on joining the invitation! Are you interested in switching workspaces and start collaboration?',
|
||||||
labels: { confirm: 'Yes, switch workspace.' },
|
labels: { confirm: 'Yes, switch workspace.' },
|
||||||
onConfirm: () => {
|
onConfirm: () => switchToWrs(invite),
|
||||||
platformContext.app.modals.openSwitchWorkspace();
|
onCancel: () => {
|
||||||
},
|
setIsRequesting(false);
|
||||||
onCancel: () => {
|
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);
|
setIsRequesting(false);
|
||||||
updateInviteId('');
|
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 (
|
return (
|
||||||
|
|||||||
@@ -127,7 +127,7 @@ const OrgManagement: FC<IModal> = ({ opened = false, onClose = () => {} }) => {
|
|||||||
case ETabTypes.Workspaces:
|
case ETabTypes.Workspaces:
|
||||||
return <Workspaces workspaces={workspaces} isFetching={isFetching} />;
|
return <Workspaces workspaces={workspaces} isFetching={isFetching} />;
|
||||||
case ETabTypes.Members:
|
case ETabTypes.Members:
|
||||||
return <Members members={members} isFetching={isFetching} />;
|
return <Members members={members} updateMembers={updateMembers} isFetching={isFetching} organizationId={organization.__ref.id}/>;
|
||||||
case ETabTypes.Billing:
|
case ETabTypes.Billing:
|
||||||
return <BillingTab />;
|
return <BillingTab />;
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -55,7 +55,12 @@ const RoleOptions = [
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const Members = ({ members = [], isFetching = false }) => {
|
const Members = ({
|
||||||
|
organizationId = '',
|
||||||
|
members = [],
|
||||||
|
updateMembers,
|
||||||
|
isFetching = false,
|
||||||
|
}) => {
|
||||||
const tableApi = useRef<TTableApi>(null);
|
const tableApi = useRef<TTableApi>(null);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -80,21 +85,38 @@ const Members = ({ members = [], isFetching = false }) => {
|
|||||||
confirm: 'Yes, change the role.',
|
confirm: 'Yes, change the role.',
|
||||||
},
|
},
|
||||||
onConfirm: () => {
|
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
|
// update the member listing after update
|
||||||
// .changeMemberRole(workspace.__ref.id, row.id, row.role.id)
|
let Index = members.findIndex((m) => m.id == row.id);
|
||||||
// .then(() => {
|
updateMembers([
|
||||||
tableApi.current.setRow({ ...row, role: row.role.id });
|
...members.slice(0, Index),
|
||||||
platformContext.app.notify.success(
|
{ ...members[Index], role: row.role.id },
|
||||||
"The member's role has been changed successfully."
|
...members.slice(Index + 1),
|
||||||
);
|
]);
|
||||||
// })
|
|
||||||
// .catch((e) => {
|
platformContext.app.notify.success(
|
||||||
// platformContext.app.notify.alert(
|
"The member's role has been changed successfully.",
|
||||||
// e.response?.data.message || e.message
|
{
|
||||||
// );
|
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
|
||||||
|
);
|
||||||
|
});
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ const ChangePassword = () => {
|
|||||||
const [confirmPassword, toggleConfirmPassword] = useState(false);
|
const [confirmPassword, toggleConfirmPassword] = useState(false);
|
||||||
|
|
||||||
const form = useForm();
|
const form = useForm();
|
||||||
const { handleSubmit, errors, getValues } = form;
|
const { handleSubmit, errors, getValues, reset } = form;
|
||||||
|
|
||||||
const _onSubmit = async (payload: {
|
const _onSubmit = async (payload: {
|
||||||
currentPassword: string;
|
currentPassword: string;
|
||||||
@@ -24,32 +24,39 @@ const ChangePassword = () => {
|
|||||||
if (isRequesting) return;
|
if (isRequesting) return;
|
||||||
|
|
||||||
setFlagIsRequesting(true);
|
setFlagIsRequesting(true);
|
||||||
// TODO: make api call
|
|
||||||
// await Rest.auth
|
await Rest.user
|
||||||
// .resetPassword({...payload})
|
.changePassword({
|
||||||
// .then((res) => {
|
currentPassword: payload.currentPassword,
|
||||||
// if ([200, 201].includes(res?.status)) {
|
newPassword: payload.newPassword,
|
||||||
// platformContext.app.notify.success(res.data?.message, {
|
})
|
||||||
// labels: { success: 'Reset password' },
|
.then((res) => res.data)
|
||||||
// });
|
.then(({ error, message }) => {
|
||||||
// platformContext.app.modals.openSignIn();
|
if (!error) {
|
||||||
// } else {
|
reset({ currentPassword: '', newPassword: '', confirmPassword: '' });
|
||||||
// platformContext.app.notify.alert(`Failed to reset password!`, {
|
platformContext.app.notify.success(message, {
|
||||||
// labels: { alert: 'Reset password' },
|
labels: { success: 'Change password' },
|
||||||
// });
|
});
|
||||||
// }
|
} else {
|
||||||
// })
|
platformContext.app.notify.alert(
|
||||||
// .catch((e) => {
|
message ?? `Failed to change password!`,
|
||||||
// platformContext.app.notify.alert(
|
{
|
||||||
// e?.response?.data?.message || e.message,
|
labels: { alert: 'Change password' },
|
||||||
// {
|
}
|
||||||
// labels: { alert: 'error!' },
|
);
|
||||||
// }
|
}
|
||||||
// );
|
})
|
||||||
// })
|
.catch((e) => {
|
||||||
// .finally(() => {
|
platformContext.app.notify.alert(
|
||||||
// setFlagIsRequesting(false);
|
e?.response?.data?.message || e.message,
|
||||||
// });
|
{
|
||||||
|
labels: { alert: 'error!' },
|
||||||
|
}
|
||||||
|
);
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
setFlagIsRequesting(false);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const _onKeyDown = (e: any) => e.key === 'Enter' && handleSubmit(_onSubmit);
|
const _onKeyDown = (e: any) => e.key === 'Enter' && handleSubmit(_onSubmit);
|
||||||
|
|||||||
@@ -11,48 +11,48 @@ import { useUserStore } from '../../../store/user';
|
|||||||
*/
|
*/
|
||||||
const UpdateProfile = () => {
|
const UpdateProfile = () => {
|
||||||
const [isRequesting, setFlagIsRequesting] = useState(false);
|
const [isRequesting, setFlagIsRequesting] = useState(false);
|
||||||
|
|
||||||
const form = useForm();
|
const form = useForm();
|
||||||
let { handleSubmit, errors } = form;
|
let { handleSubmit, errors } = form;
|
||||||
|
|
||||||
const {user} = useUserStore(s => ({
|
const { user } = useUserStore((s) => ({
|
||||||
user: s.user
|
user: s.user,
|
||||||
}))
|
}));
|
||||||
|
|
||||||
const _onSubmit = async (payload: {
|
const _onSubmit = async (payload: { name: string }) => {
|
||||||
name: string;
|
|
||||||
}) => {
|
|
||||||
if (isRequesting) return;
|
if (isRequesting) return;
|
||||||
let { name } = payload;
|
let { name } = payload;
|
||||||
|
|
||||||
|
|
||||||
setFlagIsRequesting(true);
|
setFlagIsRequesting(true);
|
||||||
// TODO: make api call
|
|
||||||
// await Rest.auth
|
await Rest.user
|
||||||
// .resetPassword({ token, new_password: password })
|
.updateProfile({ name })
|
||||||
// .then((res) => {
|
.then((res) => res.data)
|
||||||
// if ([200, 201].includes(res?.status)) {
|
.then(({ error, message }) => {
|
||||||
// platformContext.app.notify.success(res.data?.message, {
|
if (!error) {
|
||||||
// labels: { success: 'Reset password' },
|
platformContext.app.notify.success(
|
||||||
// });
|
message ?? `Your profile details are updated`,
|
||||||
// platformContext.app.modals.openSignIn();
|
{
|
||||||
// } else {
|
labels: { success: 'Update profile' },
|
||||||
// platformContext.app.notify.alert(`Failed to reset password!`, {
|
}
|
||||||
// labels: { alert: 'Reset password' },
|
);
|
||||||
// });
|
} else {
|
||||||
// }
|
platformContext.app.notify.alert(message, {
|
||||||
// })
|
labels: { alert: 'Update profile' },
|
||||||
// .catch((e) => {
|
});
|
||||||
// platformContext.app.notify.alert(
|
}
|
||||||
// e?.response?.data?.message || e.message,
|
})
|
||||||
// {
|
.catch((e) => {
|
||||||
// labels: { alert: 'error!' },
|
platformContext.app.notify.alert(
|
||||||
// }
|
e?.response?.data?.message || e.message,
|
||||||
// );
|
{
|
||||||
// })
|
labels: { alert: 'error!' },
|
||||||
// .finally(() => {
|
}
|
||||||
// setFlagIsRequesting(false);
|
);
|
||||||
// });
|
})
|
||||||
|
.finally(() => {
|
||||||
|
setFlagIsRequesting(false);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const _onKeyDown = (e: any) => e.key === 'Enter' && handleSubmit(_onSubmit);
|
const _onKeyDown = (e: any) => e.key === 'Enter' && handleSubmit(_onSubmit);
|
||||||
|
|||||||
@@ -112,6 +112,7 @@ const SIOVersionDropDown: FC<any> = ({
|
|||||||
className={cx({ 'transform rotate-180': isDropDownOpen })}
|
className={cx({ 'transform rotate-180': isDropDownOpen })}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
|
animate={false}
|
||||||
secondary
|
secondary
|
||||||
xs
|
xs
|
||||||
/>
|
/>
|
||||||
|
|||||||
10301
pnpm-lock.yaml
generated
10301
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user