add fetching token functionality

This commit is contained in:
Alex Holliday committed 2025-03-26 15:32:33 -07:00
1 parent 4d56e71691
commit 3181598aeb
1 file changed
+26 -3
+26 -3
View File
@@ -10,6 +10,7 @@ import { useSelector } from "react-redux";
import Select from "../../Inputs/Select"; import Select from "../../Inputs/Select";
import { GenericDialog } from "../../Dialog/genericDialog"; import { GenericDialog } from "../../Dialog/genericDialog";
import DataTable from "../../Table/"; import DataTable from "../../Table/";
import { useGetInviteToken } from "../../../Hooks/inviteHooks";
/** /**
* TeamPanel component manages the organization and team members, * TeamPanel component manages the organization and team members,
* providing functionalities like renaming the organization, managing team members, * providing functionalities like renaming the organization, managing team members,
@@ -20,7 +21,6 @@ import DataTable from "../../Table/";
const TeamPanel = () => { const TeamPanel = () => {
const theme = useTheme(); const theme = useTheme();
const SPACING_GAP = theme.spacing(12); const SPACING_GAP = theme.spacing(12);
const [toInvite, setToInvite] = useState({ const [toInvite, setToInvite] = useState({
@@ -34,6 +34,8 @@ const TeamPanel = () => {
const [errors, setErrors] = useState({}); const [errors, setErrors] = useState({});
const [isSendingInvite, setIsSendingInvite] = useState(false); const [isSendingInvite, setIsSendingInvite] = useState(false);
const [getInviteToken, clearToken, isLoading, error, token] = useGetInviteToken();
const headers = [ const headers = [
{ {
id: "name", id: "name",
@@ -124,6 +126,10 @@ const TeamPanel = () => {
}); });
}; };
const handleGetToken = async () => {
await getInviteToken({ email: toInvite.email, role: toInvite.role });
};
const handleInviteMember = async () => { const handleInviteMember = async () => {
if (!toInvite.email) { if (!toInvite.email) {
setErrors((prev) => ({ ...prev, email: "Email is required." })); setErrors((prev) => ({ ...prev, email: "Email is required." }));
@@ -146,7 +152,7 @@ const TeamPanel = () => {
} }
try { try {
await networkService.requestInvitationToken({ await networkService.sendInvitationToken({
email: toInvite.email, email: toInvite.email,
role: toInvite.role, role: toInvite.role,
}); });
@@ -165,6 +171,7 @@ const TeamPanel = () => {
const closeInviteModal = () => { const closeInviteModal = () => {
setIsOpen(false); setIsOpen(false);
clearToken();
setToInvite({ email: "", role: ["0"] }); setToInvite({ email: "", role: ["0"] });
setErrors({}); setErrors({});
}; };
@@ -275,6 +282,13 @@ const TeamPanel = () => {
{ _id: "user", name: "User" }, { _id: "user", name: "User" },
]} ]}
/> />
{token && <Typography>Invite link</Typography>}
{token && (
<TextInput
id="invite-token"
value={token}
/>
)}
<Stack <Stack
direction="row" direction="row"
gap={theme.spacing(4)} gap={theme.spacing(4)}
@@ -289,6 +303,15 @@ const TeamPanel = () => {
> >
Cancel Cancel
</Button> </Button>
<Button
variant="contained"
color="accent"
onClick={handleGetToken}
loading={isSendingInvite}
disabled={isDisabled}
>
Get token
</Button>
<Button <Button
variant="contained" variant="contained"
color="accent" color="accent"
@@ -296,7 +319,7 @@ const TeamPanel = () => {
loading={isSendingInvite} loading={isSendingInvite}
disabled={isDisabled} disabled={isDisabled}
> >
Send invite E-mail token
</Button> </Button>
</Stack> </Stack>
</GenericDialog> </GenericDialog>