Skip to content

Commit

Permalink
Merge pull request #568 from AI4Bharat/develop2
Browse files Browse the repository at this point in the history
Develop2
  • Loading branch information
Shruti1229 authored Mar 6, 2024
2 parents bfa1371 + ef4608a commit 7c5ba2f
Show file tree
Hide file tree
Showing 8 changed files with 361 additions and 80 deletions.
260 changes: 260 additions & 0 deletions src/common/AddNewMember.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,260 @@
import {
Button,
Checkbox,
Dialog,
DialogActions,
DialogContent,
DialogTitle,
FormControl,
Grid,
IconButton,
InputLabel,
ListItemText,
MenuItem,
OutlinedInput,
Select,
TextField,
Typography,
} from "@mui/material";
import React, { useCallback, useEffect, useState } from "react";
import CloseIcon from "@mui/icons-material/Close";
import { MenuProps } from "utils";
import {
APITransport,
CreateMemberAPI,
FetchOrganizationListAPI,
FetchUserRolesAPI,
setSnackBar,
} from "redux/actions";
import { useDispatch, useSelector } from "react-redux";
import { validateEmail } from "utils/utils";
import CustomizedSnackbars from "./Snackbar";
import Loader from "./Spinner";

const AddNewMember = ({ open, handleClose }) => {
const dispatch = useDispatch();

const [formFields, setFormFields] = useState({
orgName: "",
email: "",
roles: [],
});
const [errors, setErrors] = useState({
email: false,
});
const [loading, setLoading] = useState(false);

const snackbar = useSelector((state) => state.commonReducer.snackbar);
const userRoles = useSelector((state) => state.getUserRoles.data);
const apiStatus = useSelector((state) => state.apiStatus);

const getUserRolesList = () => {
const userObj = new FetchUserRolesAPI();
dispatch(APITransport(userObj));
};

useEffect(() => {
const { progress, success, apiType } = apiStatus;

if (!progress) {
if (success) {
if (apiType === "CREATE_MEMBER") {
setLoading(false);
handleClose();

const apiObj = new FetchOrganizationListAPI();
dispatch(APITransport(apiObj));
}
}
}

// eslint-disable-next-line
}, [apiStatus]);

useEffect(() => {
getUserRolesList();

// eslint-disable-next-line
}, []);

const handleChange = (event) => {
const {
target: { name, value },
} = event;

if (name === "email") {
const emailValidation = validateEmail(value);
setErrors((prev) => {
return {
...prev,
[name]: !emailValidation,
};
});
}

setFormFields((prev) => {
return {
...prev,
[name]: value,
};
});
};

const handleClear = () => {
setFormFields({
orgName: "",
email: "",
roles: [],
});

setErrors({
email: false,
});
};

const handleSubmit = async () => {
setLoading(true);

const { orgName, email, roles } = formFields;

const apiObj = new CreateMemberAPI(orgName, email, roles);
dispatch(APITransport(apiObj));
};

const disableForm = () => {
const { orgName, email, roles } = formFields;

if (orgName === "" || email === "" || roles.length === 0) {
return true;
}

return false;
};

const renderSnackBar = useCallback(() => {
return (
<CustomizedSnackbars
open={snackbar.open}
handleClose={() =>
dispatch(setSnackBar({ open: false, message: "", variant: "" }))
}
anchorOrigin={{ vertical: "top", horizontal: "right" }}
variant={snackbar.variant}
message={[snackbar.message]}
/>
);

//eslint-disable-next-line
}, [snackbar]);

return (
<>
{renderSnackBar()}
<Dialog
open={open}
onClose={handleClose}
fullWidth
maxWidth={"sm"}
PaperProps={{ style: { borderRadius: "10px" } }}
>
<DialogTitle variant="h4" display="flex" alignItems={"center"}>
<Typography variant="h4">Create New Members</Typography>{" "}
<IconButton
aria-label="close"
onClick={handleClose}
sx={{ marginLeft: "auto" }}
>
<CloseIcon />
</IconButton>
</DialogTitle>

<DialogContent>
<Grid container spacing={2} sx={{ paddingTop: "20px" }}>
<Grid item xs={12}>
<TextField
fullWidth
name="orgName"
label="Organization Name*"
onChange={handleChange}
value={formFields.orgName}
/>
</Grid>

<Grid item xs={12}>
<TextField
fullWidth
name="email"
label="Org Owner Email*"
onChange={handleChange}
value={formFields.email}
error={errors.email}
helperText={errors.email ? "Invalid email" : ""}
/>
</Grid>

<Grid item xs={12}>
<FormControl fullWidth>
<InputLabel id="role-select">Roles</InputLabel>
<Select
labelId="role-select"
label="Roles"
name="roles"
value={formFields.roles}
onChange={handleChange}
multiple
input={<OutlinedInput label="Roles" />}
renderValue={(selected) =>
selected.map((obj) => obj.label).join(", ")
}
MenuProps={MenuProps}
>
{userRoles.map((role) => (
<MenuItem
key={role.value}
value={role}
disabled={role.value === "ORG_OWNER"}
>
<Checkbox
checked={
formFields.roles
.map((obj) => obj.value)
.indexOf(role.value) > -1
}
/>
<ListItemText primary={role.label} />
</MenuItem>
))}
</Select>
</FormControl>
</Grid>
</Grid>
</DialogContent>

<DialogActions sx={{ p: "20px" }}>
<Button
variant="text"
onClick={handleClear}
sx={{ lineHeight: "1", borderRadius: "6px" }}
>
Clear
</Button>

<Button
autoFocus
variant="contained"
sx={{ lineHeight: "1", marginLeft: "10px", borderRadius: "8px" }}
onClick={handleSubmit}
disabled={disableForm()}
>
Create{" "}
{loading && (
<Loader size={20} margin="0 0 0 10px" color="secondary" />
)}
</Button>
</DialogActions>
</Dialog>
</>
);
};

export default AddNewMember;
2 changes: 2 additions & 0 deletions src/common/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import { TabPanel } from "./TabPanel";
import ShortcutKeys from "./ShortcutKeys";
import UnsubscribeHeader from "./UnsubscribeHeader";
import OnBoardingForm from "./OnBoardingForm";
import AddNewMember from "./AddNewMember";

export {
AddOrganizationMember,
Expand Down Expand Up @@ -96,4 +97,5 @@ export {
ShortcutKeys,
UnsubscribeHeader,
OnBoardingForm,
AddNewMember,
};
58 changes: 39 additions & 19 deletions src/containers/Admin/Dashboard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { DatasetStyle } from "styles";
import { Box, Card, Grid, Tab, Tabs, Button } from "@mui/material";
import OrganizationList from "./OrganizationList";
import MemberList from "./MemberList";
import { AddOrganizationMember } from "common";
import { AddNewMember, AddOrganizationMember } from "common";
import AdminLevelReport from "./AdminLevelReport";

//Apis
Expand Down Expand Up @@ -40,6 +40,7 @@ const DashBoard = () => {
const [value, setValue] = useState(0);
const [addUserDialog, setAddUserDialog] = useState(false);
const [newMemberEmail, setNewMemberEmail] = useState("");
const [openMemberDialog, setOpenMemberDialog] = useState(false);

const addNewMemberHandler = async () => {
const data = {
Expand Down Expand Up @@ -80,24 +81,36 @@ const DashBoard = () => {
index={0}
style={{ textAlign: "center", maxWidth: "100%" }}
>
<Box
display={"flex"}
flexDirection="Column"
justifyContent="center"
alignItems="center"
>
<Button
className={classes.projectButton}
onClick={() => navigate(`/admin/create-new-org`)}
variant="contained"
>
Add New Organization
</Button>

<div className={classes.workspaceTables} style={{ width: "100%" }}>
<OrganizationList />
</div>
</Box>
<Grid container direction="row" sx={{ my: 4 }}>
<Grid item md={6} xs={12}>
<Button
style={{ marginRight: "10px", width: "100%" }}
variant="contained"
onClick={() => navigate(`/admin/create-new-org`)}
>
Add New Organization
</Button>
</Grid>

<Grid item md={6} xs={12}>
<Button
style={{ marginLeft: "10px", width: "100%" }}
variant="contained"
onClick={() => setOpenMemberDialog(true)}
>
Create New Members
</Button>
</Grid>

<Grid item md={12} xs={12} style={{ width: "100%" }}>
<div
className={classes.workspaceTables}
style={{ width: "100%" }}
>
<OrganizationList />
</div>
</Grid>
</Grid>
</TabPanel>

<TabPanel
Expand Down Expand Up @@ -175,6 +188,13 @@ const DashBoard = () => {
isAdmin={true}
/>
)}

{openMemberDialog && (
<AddNewMember
open={openMemberDialog}
handleClose={() => setOpenMemberDialog(false)}
/>
)}
</Grid>
);
};
Expand Down
30 changes: 1 addition & 29 deletions src/containers/Organization/OrgLevelTaskList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -1083,35 +1083,7 @@ const OrgLevelTaskList = () => {
handleDialogClose("exportDialog");

const apiObj = new BulkExportVoiceoverTasksAPI(selectedBulkTaskid);
try {
const res = await fetch(apiObj.apiEndPoint(), {
method: "GET",
headers: apiObj.getHeaders().headers,
});

if (res.ok) {
const resp = await res.blob();
exportZip(resp);
} else {
const resp = await res.json();

dispatch(
setSnackBar({
open: true,
message: resp.message,
variant: "error",
})
);
}
} catch (error) {
dispatch(
setSnackBar({
open: true,
message: "Something went wrong!!",
variant: "error",
})
);
}
dispatch(APITransport(apiObj));
};

const handleExportRadioButtonChange = (event) => {
Expand Down
Loading

0 comments on commit 7c5ba2f

Please sign in to comment.