I have an object called "staff". The staff is then mapped to show all of the staff users and render a list. I need to somehow, get the name of the staff I want to deactivate, and show it in a modal. The code:
const [staff, setStaff] = useState([]);
const handleOpen = () => {
setOpen(true);
};
const handleClose = () => {
setOpen(false);
};
const getStaff = async () => {
try {
const r = await apiClient.get(
endpoints.businessUsersDemographics(idBusiness)
);
if (r.data) {
const rawUsers = r.data.filter((d) => d.ic_active === true);
const staff = rawUsers.filter(
(u) => u.cd_user_type === userType["staff"]`enter code here`
);
setStaff(staff);
}
} catch (err) {
console.log(err);
}
};
return (
<>
{staff.length > 0 &&
staff.map((u) => (
<UserContainer key={u.id_user}>
<UserName>
{u.ds_firstname} {u.ds_lastname}
</UserName>
<UserInfo>{u.ds_mail}</UserInfo>
<UserInfo>{u.ds_title}</UserInfo>
<EditIcon
onClick={() => handleEditUser(u)}
className={classes.icon}
/>
<ClearIcon
className={`${classes.icon} ${classes.delete}`}
onClick={handleOpen}
/>
</UserContainer>
))}
<Modal
aria-labelledby="transition-modal-title"
aria-describedby="transition-modal-description"
className={classes.modal}
open={open}
onClose={handleClose}
closeAfterTransition
BackdropComponent={Backdrop}
BackdropProps={{
timeout: 500,
}}
>
<Fade in={open}>
<div className={classes.continueModal}>
<p>You’re deactivating the following user from the business.</p>
<UserName>No idea how to show the staff's name</UserName>
<p>Would you like to continue?</p>
<Button
variant="contained"
color="primary"
type="submit"
style={{
width: "10rem",
marginTop: theme.spacing(3),
}}
>
Confirm
</Button>
<Button
variant="contained"
color="primary"
type="submit"
style={{
width: "10rem",
marginTop: theme.spacing(3),
}}
>
Cancel
</Button>
</div>
</Fade>
</Modal>
</>
);
I'm not sure how to render the name of the staff I want to deactivate. I tried to do this: Dynamic content with React js Modal but I got a "Error: Too many re-renders. React limits the number of renders to prevent an infinite loop.". Here are some screenshots of the UI:
The list of users I got from mapping the staff object
The modal where I should show the names
How could I do so? I'm completely confused. Thanks!