Add loading state to team panel
This commit is contained in:
1 parent
899111e48b
commit
e00938e12a
1 file changed
+34
-34
@@ -1,25 +1,13 @@
|
|||||||
import { useTheme } from "@emotion/react";
|
import { useTheme } from "@emotion/react";
|
||||||
import TabPanel from "@mui/lab/TabPanel";
|
import TabPanel from "@mui/lab/TabPanel";
|
||||||
import {
|
import { Button, ButtonGroup, Modal, Stack, Typography } from "@mui/material";
|
||||||
Box,
|
|
||||||
Button,
|
|
||||||
ButtonGroup,
|
|
||||||
Divider,
|
|
||||||
IconButton,
|
|
||||||
Modal,
|
|
||||||
Stack,
|
|
||||||
TextField,
|
|
||||||
Typography,
|
|
||||||
} from "@mui/material";
|
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import EditSvg from "../../../assets/icons/edit.svg?react";
|
|
||||||
import Field from "../../Inputs/Field";
|
import Field from "../../Inputs/Field";
|
||||||
import { credentials } from "../../../Validation/validation";
|
import { credentials } from "../../../Validation/validation";
|
||||||
import { networkService } from "../../../main";
|
import { networkService } from "../../../main";
|
||||||
import { createToast } from "../../../Utils/toastUtils";
|
import { createToast } from "../../../Utils/toastUtils";
|
||||||
import { useSelector } from "react-redux";
|
import { useSelector } from "react-redux";
|
||||||
import BasicTable from "../../BasicTable";
|
import BasicTable from "../../BasicTable";
|
||||||
import Remove from "../../../assets/icons/trash-bin.svg?react";
|
|
||||||
import Select from "../../Inputs/Select";
|
import Select from "../../Inputs/Select";
|
||||||
import LoadingButton from "@mui/lab/LoadingButton";
|
import LoadingButton from "@mui/lab/LoadingButton";
|
||||||
|
|
||||||
@@ -54,6 +42,7 @@ const TeamPanel = () => {
|
|||||||
const [members, setMembers] = useState([]);
|
const [members, setMembers] = useState([]);
|
||||||
const [filter, setFilter] = useState("all");
|
const [filter, setFilter] = useState("all");
|
||||||
const [errors, setErrors] = useState({});
|
const [errors, setErrors] = useState({});
|
||||||
|
const [isSendingInvite, setIsSendingInvite] = useState(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchTeam = async () => {
|
const fetchTeam = async () => {
|
||||||
@@ -173,6 +162,7 @@ const TeamPanel = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleInviteMember = async () => {
|
const handleInviteMember = async () => {
|
||||||
|
setIsSendingInvite(true);
|
||||||
if (!toInvite.role.includes("user") || !toInvite.role.includes("admin"))
|
if (!toInvite.role.includes("user") || !toInvite.role.includes("admin"))
|
||||||
setToInvite((prev) => ({ ...prev, role: ["user"] }));
|
setToInvite((prev) => ({ ...prev, role: ["user"] }));
|
||||||
|
|
||||||
@@ -185,24 +175,28 @@ const TeamPanel = () => {
|
|||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
setErrors((prev) => ({ ...prev, email: error.details[0].message }));
|
setErrors((prev) => ({ ...prev, email: error.details[0].message }));
|
||||||
} else
|
return;
|
||||||
try {
|
}
|
||||||
await networkService.requestInvitationToken(
|
|
||||||
authToken,
|
|
||||||
toInvite.email,
|
|
||||||
toInvite.role
|
|
||||||
);
|
|
||||||
|
|
||||||
closeInviteModal();
|
try {
|
||||||
createToast({
|
await networkService.requestInvitationToken(
|
||||||
body: "Member invited. They will receive an email with details on how to create their account.",
|
authToken,
|
||||||
});
|
toInvite.email,
|
||||||
} catch (error) {
|
toInvite.role
|
||||||
createToast({
|
);
|
||||||
body: error.message || "Unknown error.",
|
closeInviteModal();
|
||||||
});
|
createToast({
|
||||||
}
|
body: "Member invited. They will receive an email with details on how to create their account.",
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
createToast({
|
||||||
|
body: error.message || "Unknown error.",
|
||||||
|
});
|
||||||
|
} finally {
|
||||||
|
setIsSendingInvite(false);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const closeInviteModal = () => {
|
const closeInviteModal = () => {
|
||||||
setIsOpen(false);
|
setIsOpen(false);
|
||||||
setToInvite({ email: "", role: ["0"] });
|
setToInvite({ email: "", role: ["0"] });
|
||||||
@@ -307,13 +301,14 @@ const TeamPanel = () => {
|
|||||||
</Button>
|
</Button>
|
||||||
</ButtonGroup>
|
</ButtonGroup>
|
||||||
</Stack>
|
</Stack>
|
||||||
<Button
|
<LoadingButton
|
||||||
|
loading={isSendingInvite}
|
||||||
variant="contained"
|
variant="contained"
|
||||||
color="primary"
|
color="primary"
|
||||||
onClick={() => setIsOpen(true)}
|
onClick={() => setIsOpen(true)}
|
||||||
>
|
>
|
||||||
Invite a team member
|
Invite a team member
|
||||||
</Button>
|
</LoadingButton>
|
||||||
</Stack>
|
</Stack>
|
||||||
<BasicTable
|
<BasicTable
|
||||||
data={tableData}
|
data={tableData}
|
||||||
@@ -389,14 +384,19 @@ const TeamPanel = () => {
|
|||||||
mt={theme.spacing(8)}
|
mt={theme.spacing(8)}
|
||||||
justifyContent="flex-end"
|
justifyContent="flex-end"
|
||||||
>
|
>
|
||||||
<Button variant="text" color="info" onClick={closeInviteModal}>
|
<LoadingButton
|
||||||
|
loading={isSendingInvite}
|
||||||
|
variant="text"
|
||||||
|
color="info"
|
||||||
|
onClick={closeInviteModal}
|
||||||
|
>
|
||||||
Cancel
|
Cancel
|
||||||
</Button>
|
</LoadingButton>
|
||||||
<LoadingButton
|
<LoadingButton
|
||||||
variant="contained"
|
variant="contained"
|
||||||
color="primary"
|
color="primary"
|
||||||
onClick={handleInviteMember}
|
onClick={handleInviteMember}
|
||||||
loading={false}
|
loading={isSendingInvite}
|
||||||
disabled={Object.keys(errors).length !== 0}
|
disabled={Object.keys(errors).length !== 0}
|
||||||
>
|
>
|
||||||
Send invite
|
Send invite
|
||||||
|
|||||||
Reference in new issue
Block a user