diff --git a/src/Admin/Pages/Pages/SubPages/BlockedUsers.js b/src/Admin/Pages/Pages/SubPages/BlockedUsers.js index c89b08bdbc5642225bb3bd45a0eb595db831964b..705a4c58ea279df20418bc84403be48cd5925688 100644 --- a/src/Admin/Pages/Pages/SubPages/BlockedUsers.js +++ b/src/Admin/Pages/Pages/SubPages/BlockedUsers.js @@ -47,606 +47,494 @@ import styled from "styled-components" import { apiDomain } from '../../../../env'; import noAvatar from "../../../../img/default_profile.png"; -let currPage = 0; //var that controlls the current page that we are -let currContentFilter = 1; -let transformListToAsc = false; - const StyledTableCell = withStyles((theme) => ({ - head: { - backgroundColor: theme.palette.common.black, - color: theme.palette.common.white, - }, - body: { - fontSize: 14, - }, + head: { + backgroundColor: theme.palette.common.black, + color: theme.palette.common.white, + }, + body: { + fontSize: 14, + }, }))(TableCell); const StyledTableRow = withStyles((theme) => ({ - root: { - '&:nth-of-type(odd)': { - backgroundColor: theme.palette.action.hover, - }, + root: { + '&:nth-of-type(odd)': { + backgroundColor: theme.palette.action.hover, }, + }, }))(TableRow); const BlockedUsers = () => { - const AddOneLenght = ['']; - const WINDOW_WIDTH = window.innerWidth - const [error, setError] = useState(null); //Necessary to consult the API, catch errors - const [isLoaded, setIsLoaded] = useState(false); //Necessary to consult the API, wait until complete - const [items, setItems] = useState([]); //Necessary to consult the API, data - const [isLoadingMoreItems, setIsLoadingMoreItems] = useState(false) - const [isUpdating, setIsUpdating] = useState(false) - - const [snackInfo, setSnackInfo] = useState({ - message: '', - icon: '', - open: false, - color: '', - }) - - const StateOptions = [ - { - id: 1, - name: "Semanal" - }, - { - id: 2, - name: "Permanente" - } - ]; - - // Handle snack infos - const HandleSnack = (message, state, icon, color) => { - setSnackInfo({ - message: message, - icon: icon, - open: state, - color: color - }) + const ADD_ONE_LENGHT = ['']; + const WINDOW_WIDTH = window.innerWidth + const [error, setError] = useState(null); //Necessary to consult the API, catch errors + const [isLoaded, setIsLoaded] = useState(false); //Necessary to consult the API, wait until complete + const [items, setItems] = useState([]); //Necessary to consult the API, data + const [isLoadingMoreItems, setIsLoadingMoreItems] = useState(false) + const [isUpdating, setIsUpdating] = useState(false) + const [stateOpt, setStateOpt] = useState(1) + const [currPage, setCurrPage] = useState(0) + + const [snackInfo, setSnackInfo] = useState({ + message: '', + icon: '', + open: false, + color: '', + }) + + const StateOptions = [ + { + name: 1, + value: "Semanal" + }, + { + name: 2, + value: "Permanente" } - - const LoadMoreItens = async (api) => { - setIsLoadingMoreItems(true) - getRequest( - api, - (data, header) => { - const arrData = [...data] - if (arrData.length === 0) { - HandleSnack('Não há mais dados para serem carregados', true, 'warning', '#FFC125') - } else { - const arrItems = [...items] - arrItems.pop(); //Deleting the last position, that was used to display the button of load more items - const arrResult = arrItems.concat(arrData) - setItems(arrResult.concat(AddOneLenght)) - } - setIsLoadingMoreItems(false) - }, - (error) => { - HandleSnack('Erro ao carregar os dados', true, 'warning', '#FA8072') - setIsLoadingMoreItems(false) - } - ) + ]; + + // Handle snack infos + const HandleSnack = (message, state, icon, color) => { + setSnackInfo({ + message: message, + icon: icon, + open: state, + color: color + }) + } + + const handleChange = (event) => { + const type = event.target.value + setStateOpt(type) + } + + const BlockStatus = (status) => { + switch (status) { + case "blocked": + return ( + <Paper + style={{ + textAlign: "center", + padding: "0.5em", + backgroundColor: "#FF8C00", + fontWeight: "500", + color: "#FFFAFA", + }} + > + SEMANAL + </Paper> + ); + case "banished": + return ( + <Paper + style={{ + textAlign: "center", + padding: "0.5em", + backgroundColor: "red", + fontWeight: "500", + color: "#FFFAFA", + }} + > + PERMANENTE + </Paper> + ); + default: + return ( + <Paper + style={{ + textAlign: "center", + padding: "0.5em", + backgroundColor: "#797D7F", + fontWeight: "500", + color: "#FFFAFA", + }} + > + Não avaliado + </Paper> + ); } - - const handleChange = (event) => { - const type = event.target.value - switch (type) { - case "Semanal": - currPage = 0; - currContentFilter = 1; - getRequest( - Url('users', `"state" : "${currContentFilter}"`, `${currPage}`, 'ASC'), - (data, header) => { - HandleSnack("Filtro aplicado com sucesso!", true, 'success', '#228B22') - const arrData = [...data] - setItems(arrData.concat(AddOneLenght)) - setIsUpdating(false) - }, - (error) => { - HandleSnack('Erro ao carregar os dados', true, 'warning', '#FA8072') - setIsUpdating(false) - } - ) - break; - case "Permanente": - currPage = 0; - currContentFilter = 2; - getRequest( - Url('users', `"state" : "${currContentFilter}"`, `${currPage}`, 'ASC'), - (data, header) => { - HandleSnack("Filtro aplicado com sucesso!", true, 'success', '#228B22') - const arrData = [...data] - setItems(arrData.concat(AddOneLenght)) - setIsUpdating(false) - }, - (error) => { - HandleSnack('Erro ao carregar os dados', true, 'warning', '#FA8072') - setIsUpdating(false) - } - ) - break; - default: - currPage = 0; - currContentFilter = 1; - getRequest( - Url('users', `"state" : "${currContentFilter}"`, `${currPage}`, 'ASC'), - (data, header) => { - HandleSnack("Filtro aplicado com sucesso!", true, 'success', '#228B22') - const arrData = [...data] - setItems(arrData.concat(AddOneLenght)) - setIsUpdating(false) - }, - (error) => { - HandleSnack('Erro ao carregar os dados', true, 'warning', '#FA8072') - setIsUpdating(false) - } - ) - break; + }; + + const ReactiveUser = (userId, index) => { + putRequest( + `/users/${userId}/reactivate_user`, + {}, + (data) => { + if (data.errors) + HandleSnack('Erro!', true, 'warning', '#FA8072') + else { + HandleSnack('Usuário foi reativado com sucesso!', true, 'success', '#228B22') + removeItemFromList(index) + setCurrPage(0) } - } - - const InvertList = async () => { - transformListToAsc = !transformListToAsc - currPage = 0 - if (transformListToAsc) { - getRequest( - Url('users', `"state" : "${currContentFilter}"`, `${currPage}`, 'ASC'), - (data, header) => { - const arrData = [...data] - setItems(arrData.concat(AddOneLenght)) - }, - (error) => { - HandleSnack('Erro ao carregar os dados', true, 'warning', '#FA8072') - } - ) + }, + (error) => { + HandleSnack('Erro!', true, 'warning', '#FA8072') + } + ) + } + + const removeItemFromList = (index) => { + const copyList = [...items] + copyList.splice(index, 1) + setItems(copyList) + } + + const DisplayDate = (date) => { + const convertedData = moment.utc(date); + return moment(convertedData) + .format("LLL") + .toString(); + }; + + useEffect(() => { + if (currPage === 0) + setIsLoaded(false) + else + setIsLoadingMoreItems(true) + getRequest( + Url('users', `"state" : ${stateOpt}`, currPage, 'DESC'), + + (data, header) => { + const arrData = [...data] + if (arrData.length === 0) { + HandleSnack('Não há mais dados para serem carregados', true, 'warning', '#FFC125') } else { - getRequest( - Url('users', `"state" : "${currContentFilter}"`, `${currPage}`, 'DESC'), - (data, header) => { - const arrData = [...data] - setItems(arrData.concat(AddOneLenght)) - }, - (error) => { - HandleSnack('Erro ao carregar os dados', true, 'warning', '#FA8072') - } - ) + const arrItems = [...items] + if (currPage === 0) { + setItems(arrData.concat(ADD_ONE_LENGHT)) + } + else { + arrItems.pop(); //Deleting the last position, that was used to display the button of load more items + const arrResult = arrItems.concat(arrData) + setItems(arrResult.concat(ADD_ONE_LENGHT)) + } } - } - - const UpdateHandler = async (api) => { - setIsUpdating(true) - getRequest( - api, - (data, header) => { - HandleSnack('A lista de dados foi atualizada', true, 'success', '#228B22') - const arrData = [...data] - setItems(arrData.concat(AddOneLenght)) - setIsUpdating(false) - }, - (error) => { - HandleSnack('Erro ao carregar os dados', true, 'warning', '#FA8072') - setIsUpdating(false) - } - ) - } - - const BlockStatus = (status) => { - switch (status) { - case 1: - return ( - <Paper - style={{ - textAlign: "center", - padding: "0.5em", - backgroundColor: "#FF8C00", - fontWeight: "500", - color: "#FFFAFA", - }} - > - SEMANAL - </Paper> - ); - case 2: - return ( - <Paper - style={{ - textAlign: "center", - padding: "0.5em", - backgroundColor: "red", - fontWeight: "500", - color: "#FFFAFA", + setIsLoaded(true) + setIsLoadingMoreItems(false) + }, + (error) => { + HandleSnack('Erro ao carregar os dados', true, 'warning', '#FA8072') + setIsLoadingMoreItems(false) + setIsLoaded(true) + setError(true) + } + ) + }, [currPage, stateOpt]) + + if (error) { + return <div>Error: {error.message}</div>; + } else if (!isLoaded) { + return <LoadingSpinner text="Carregando..." /> + } else { + + //Words in the top part of the table + const topTable = ['ID', 'ESTADO', 'NAME', 'EMAIL', 'BLOQUEADO EM', 'AÇÕES']; + if (WINDOW_WIDTH <= 899) { + return ( + <div> + <SnackBar + severity={snackInfo.icon} + text={snackInfo.message} + snackbarOpen={snackInfo.open} + color={snackInfo.color} + handleClose={() => setSnackInfo({ + message: '', + icon: '', + open: false, + color: '' + })} + /> + <Paper style={{ padding: '1em' }}> + <Grid container direction="row" alignItems="center"> + <Grid container spacing={3} > + <Grid item xs={12}> + <Typography variant="h4"> + Lista de usuários bloqueados + </Typography> + </Grid> + <Grid + item + xs={12} + + > + <Grid container justify="flex-start" spacing={3}> + <Grid item> + <Button + variant="contained" + color="secondary" + disabled={isUpdating} + onClick={() => { + setCurrPage(0) }} + startIcon={<UpdateRoundedIcon />} + > + { + isUpdating ? <CircularProgress size={24} /> : 'Atualizar' + } + </Button> + </Grid> + </Grid> + </Grid> + </Grid> + <Grid item> + <TextField + select + label="Estado de bloqueio" + onChange={handleChange} + helperText="Por favor, selecione uma das opções" + > + {StateOptions.map((option, index) => ( + <MenuItem + key={option.value} + value={option.name} + name={option.value} > - PERMANENTE - </Paper> - ); - default: - return ( - <Paper + {option.value} + </MenuItem> + ))} + </TextField> + </Grid> + + </Grid> + </Paper> + + <div style={{ height: '2em' }}></div> + + {items.map((row, index) => + index === items.length - 1 ? ( + <StyledDivButton> + <Button + key={index} + color="primary" + variant="text" + // disabled={isLoadingMoreItems} + startIcon={<AddRoundedIcon />} + disabled={isLoadingMoreItems} + onClick={() => { + setCurrPage(currPage + 1) + }} + > + {isLoadingMoreItems ? ( + <CircularProgress size={24} /> + ) : ( + "Carregar mais itens" + )} + </Button> + </StyledDivButton> + ) : ( + <> + <MobileList + key={index} + title={row.name} + subtitle={row.id} + backColor={"#e81f4f"} + avatar={ + <img + src={row.avatar ? apiDomain + row.avatar : noAvatar} + alt="user avatar" style={{ - textAlign: "center", - padding: "0.5em", - backgroundColor: "#797D7F", - fontWeight: "500", - color: "#FFFAFA", + height: "100%", + width: "100%", + borderRadius: "50%", }} - > - Não avaliado - </Paper> - ); - } - }; - - const ReactiveUser = (userId) => { - putRequest( - `/users/${userId}/reactivate_user`, - {}, - (data) => { - if (data.errors) - HandleSnack('Erro!', true, 'warning', '#FA8072') - else { - currPage = 0 - HandleSnack('Usuário foi reativado com sucesso!', true, 'success', '#228B22') - UpdateHandler(Url('users', `"state" : "${currContentFilter}"`, `${currPage}`, 'DESC')) - } - }, - (error) => { - HandleSnack('Erro!', true, 'warning', '#FA8072') - } - ) - } - - const DisplayDate = (date) => { - const convertedData = moment.utc(date); - return moment(convertedData) - .format("LLL") - .toString(); - }; - - useEffect(() => { - getRequest( - Url('users', `"state" : "${currContentFilter}"`, '0', 'DESC'), - (data, header) => { - setIsLoaded(true); - setItems(data.concat(AddOneLenght)); - }, - (error) => { - setError(true); - } - ) - }, []); - - - if (error) { - return <div>Error: {error.message}</div>; - } else if (!isLoaded) { - return <LoadingSpinner text="Carregando..." /> - } else { - - //Words in the top part of the table - const topTable = ['ID', 'ESTADO', 'NAME', 'EMAIL', 'BLOQUEADO EM', 'AÇÕES']; - if (WINDOW_WIDTH <= 899) { - return ( - <div> - <SnackBar - severity={snackInfo.icon} - text={snackInfo.message} - snackbarOpen={snackInfo.open} - color={snackInfo.color} - handleClose={() => setSnackInfo({ - message: '', - icon: '', - open: false, - color: '' - })} - /> - <Paper style={{ padding: '1em' }}> - <Grid container direction="row" alignItems="center"> - <Grid container spacing={3} > - <Grid item xs={12}> - <Typography variant="h4"> - Lista de usuários bloqueados - </Typography> - </Grid> - <Grid - item - xs={12} - - > - <Grid container justify="flex-start" spacing={3}> - <Grid item> - <Button - variant="contained" - color="secondary" - disabled={isUpdating} - onClick={() => { - currPage = 0 - transformListToAsc = false - UpdateHandler(Url('users', `"state" : "${currContentFilter}"`, `${currPage}`, 'DESC')) - }} - startIcon={<UpdateRoundedIcon />} - > - { - isUpdating ? <CircularProgress size={24} /> : 'Atualizar' - } - </Button> - </Grid> - </Grid> - </Grid> - </Grid> - <Grid item> - <TextField - select - label="Estado de bloqueio" - onChange={handleChange} - helperText="Por favor, selecione uma das opções" - > - {StateOptions.map((option, index) => ( - <MenuItem - key={option.id} - value={option.name} - name={option.id} - > - {option.name} - </MenuItem> - ))} - </TextField> - </Grid> - - </Grid> - </Paper> - - <div style={{ height: '2em' }}></div> - - {items.map((row, index) => - index === items.length - 1 ? ( - <StyledDivButton> - <Button - key={index} - color="primary" - variant="text" - // disabled={isLoadingMoreItems} - startIcon={<AddRoundedIcon />} - disabled={isLoadingMoreItems} - onClick={() => { - currPage++ - if (transformListToAsc) { - LoadMoreItens(Url('users', `"state" : "${currContentFilter}"`, `${currPage}`, 'ASC')) - } else { - LoadMoreItens(Url('users', `"state" : "${currContentFilter}"`, `${currPage}`, 'DESC')) - } - }} - > - {isLoadingMoreItems ? ( - <CircularProgress size={24} /> - ) : ( - "Carregar mais itens" - )} - </Button> - </StyledDivButton> - ) : ( - <> - <MobileList - key={index} - title={row.name} - subtitle={row.id} - backColor={"#e81f4f"} - avatar={ - <img - src={row.avatar ? apiDomain + row.avatar : noAvatar} - alt="user avatar" - style={{ - height: "100%", - width: "100%", - borderRadius: "50%", - }} - /> - } - href={`/admin/user/${row.id}`} - reset={() => { - currPage = 0; transformListToAsc = false; currContentFilter = 1 - }} - data={ - [ - { - title: "Email", - subtitle: row.email ? - <Link to={`/admin/sendEmail/${row.email}`} style={{ textDecoration: 'none' }}> - <Button - variant='text' - color='primary' - startIcon={<EmailRoundedIcon />} - > - {row.email} - </Button> - </Link> : null - - }, - { - title: "Estado", - subtitle: BlockStatus(currContentFilter) - }, - { - title: "Ações rápidas", - subtitle: <Button - style={{ width: "100%", marginBottom: "0.5em" }} - variant="contained" - color="secondary" - startIcon={<RemoveCircleOutlineRoundedIcon />} - onClick={() => ReactiveUser(row.id)} - > - Desbloquear + /> + } + href={`/admin/user/${row.id}`} + reset={() => { + }} + data={ + [ + { + title: "Email", + subtitle: row.email ? + <Link to={`/admin/sendEmail/${row.email}`} style={{ textDecoration: 'none' }}> + <Button + variant='text' + color='primary' + startIcon={<EmailRoundedIcon />} + > + {row.email} + </Button> + </Link> : null + + }, + { + title: "Estado", + subtitle: BlockStatus(row.state) + }, + { + title: "Ações rápidas", + subtitle: <Button + style={{ width: "100%", marginBottom: "0.5em" }} + variant="contained" + color="secondary" + startIcon={<RemoveCircleOutlineRoundedIcon />} + onClick={() => ReactiveUser(row.id, index)} + > + Desbloquear </Button> - } - ] - } - /> - <div style={{ height: "0.5em" }} /> - </> - ) - )} - </div> - ) - } - else { - return ( - <div> - <SnackBar - severity={snackInfo.icon} - text={snackInfo.message} - snackbarOpen={snackInfo.open} - color={snackInfo.color} - handleClose={() => setSnackInfo({ - message: '', - icon: '', - open: false, - color: '' - })} - /> - <Paper style={{ padding: '1em' }}> - <Grid container direction="row" alignItems="center"> - <Grid container spacing={3} > - <Grid item xs={6}> - <Typography variant="h4"> - Lista de usuários bloqueados + } + ] + } + /> + <div style={{ height: "0.5em" }} /> + </> + ) + )} + </div> + ) + } + else { + return ( + <div> + <SnackBar + severity={snackInfo.icon} + text={snackInfo.message} + snackbarOpen={snackInfo.open} + color={snackInfo.color} + handleClose={() => setSnackInfo({ + message: '', + icon: '', + open: false, + color: '' + })} + /> + <Paper style={{ padding: '1em' }}> + <Grid container direction="row" alignItems="center"> + <Grid container spacing={3} > + <Grid item xs={6}> + <Typography variant="h4"> + Lista de usuários bloqueados </Typography> - </Grid> - <Grid - item - xs={6} - > - <Grid container justify="flex-end" spacing={3}> - <Grid item> - <Button - variant="contained" - color="secondary" - disabled={isUpdating} - onClick={() => { - currPage = 0 - transformListToAsc = false - UpdateHandler(Url('users', `"state" : "${currContentFilter}"`, `${currPage}`, 'DESC')) - }} - startIcon={<UpdateRoundedIcon />} - > - { - isUpdating ? <CircularProgress size={24} /> : 'Atualizar' - } - </Button> - </Grid> - </Grid> - </Grid> - </Grid> - <Grid item> - <TextField - select - label="Estado de bloqueio" - onChange={handleChange} - helperText="Por favor, selecione uma das opções" - > - {StateOptions.map((option, index) => ( - <MenuItem - key={option.id} - value={option.name} - name={option.id} - > - {option.name} - </MenuItem> - ))} - </TextField> - </Grid> - - </Grid> - </Paper> - - <div style={{ height: '2em' }}></div> - - <TableData - top={topTable} - onIconPressed={InvertList} + </Grid> + <Grid + item + xs={6} + > + <Grid container justify="flex-end" spacing={3}> + <Grid item> + <Button + variant="contained" + color="secondary" + disabled={isUpdating} + onClick={() => { + setCurrPage(0) + }} + startIcon={<UpdateRoundedIcon />} + > + { + isUpdating ? <CircularProgress size={24} /> : 'Atualizar' + } + </Button> + </Grid> + </Grid> + </Grid> + </Grid> + <Grid item> + <TextField + select + label="Estado de bloqueio" + onChange={handleChange} + helperText="Por favor, selecione uma das opções" + > + {StateOptions.map((option, index) => ( + <MenuItem + key={option.value} + value={option.name} + name={option.value} > - <TableBody> - {items.map((row, index) => ( - index === items.length - 1 ? - <StyledTableRow key={index}> - {/* Button to load more data */} - <StyledTableCell> - <Button - color='primary' - variant='text' - disabled={isLoadingMoreItems} - startIcon={<AddRoundedIcon />} - onClick={() => { - currPage++ - if (transformListToAsc) { - LoadMoreItens(Url('users', `"state" : "${currContentFilter}"`, `${currPage}`, 'ASC')) - } else { - LoadMoreItens(Url('users', `"state" : "${currContentFilter}"`, `${currPage}`, 'DESC')) - } - }} - > - { - isLoadingMoreItems ? <CircularProgress size={24} /> : 'Carregar mais itens' - } - </Button> - </StyledTableCell> - </StyledTableRow> - - : - - <StyledTableRow key={index}> - <StyledTableCell component="th" scope="row">{row.id}</StyledTableCell> - <StyledTableCell align="right"> - {BlockStatus(currContentFilter)} - </StyledTableCell> - <StyledTableCell align="right">{row.name}</StyledTableCell> - <StyledTableCell align="right"> - { - row.email ? - <Link to={`/admin/sendEmail/${row.email}`} style={{ textDecoration: 'none' }}> - <Button - variant='text' - color='primary' - startIcon={<EmailRoundedIcon />} - > - {row.email} - </Button> - </Link> : null - } - </StyledTableCell> - <StyledTableCell align="right"> - {DisplayDate(row.suspended_at)} - </StyledTableCell> - <StyledTableCell align="right"> - <Button - style={{ width: "100%", marginBottom: "0.5em" }} - variant="contained" - color="secondary" - startIcon={<RemoveCircleOutlineRoundedIcon />} - onClick={() => ReactiveUser(row.id)} - > - Desbloquear + {option.value} + </MenuItem> + ))} + </TextField> + </Grid> + + </Grid> + </Paper> + + <div style={{ height: '2em' }}></div> + + <TableData + top={topTable} + > + <TableBody> + {items.map((row, index) => ( + index === items.length - 1 ? + <StyledTableRow key={index}> + {/* Button to load more data */} + <StyledTableCell> + <Button + color='primary' + variant='text' + disabled={isLoadingMoreItems} + startIcon={<AddRoundedIcon />} + onClick={() => { + setCurrPage(currPage + 1) + }} + > + { + isLoadingMoreItems ? <CircularProgress size={24} /> : 'Carregar mais itens' + } + </Button> + </StyledTableCell> + </StyledTableRow> + + : + + <StyledTableRow key={index}> + <StyledTableCell component="th" scope="row">{row.id}</StyledTableCell> + <StyledTableCell align="right"> + {BlockStatus(row.state)} + </StyledTableCell> + <StyledTableCell align="right">{row.name}</StyledTableCell> + <StyledTableCell align="right"> + { + row.email ? + <Link to={`/admin/sendEmail/${row.email}`} style={{ textDecoration: 'none' }}> + <Button + variant='text' + color='primary' + startIcon={<EmailRoundedIcon />} + > + {row.email} + </Button> + </Link> : null + } + </StyledTableCell> + <StyledTableCell align="right"> + {DisplayDate(row.suspended_at)} + </StyledTableCell> + <StyledTableCell align="right"> + <Button + style={{ width: "100%", marginBottom: "0.5em" }} + variant="contained" + color="secondary" + startIcon={<RemoveCircleOutlineRoundedIcon />} + onClick={() => ReactiveUser(row.id, index)} + > + Desbloquear </Button> - <Link to={`/admin/user/${row.id}`}> - <Button - onClick={() => { currPage = 0; transformListToAsc = false; currContentFilter = 1 }} - style={{ width: "100%" }} - variant="contained" - color="primary" - startIcon={<VisibilityIcon />} - > - Visualizar + <Link to={`/admin/user/${row.id}`}> + <Button + style={{ width: "100%" }} + variant="contained" + color="primary" + startIcon={<VisibilityIcon />} + > + Visualizar </Button> - </Link> - </StyledTableCell> - </StyledTableRow> - ))} - </TableBody> - </TableData> - </div> - ) - } + </Link> + </StyledTableCell> + </StyledTableRow> + ))} + </TableBody> + </TableData> + </div> + ) } + } } diff --git a/src/Admin/Pages/Pages/SubPages/Collections.js b/src/Admin/Pages/Pages/SubPages/Collections.js index 14731dcfc19d4092c8b061f600e65c6c14587108..626aeed6d473b5a047c7f2b525502c42f03075c1 100644 --- a/src/Admin/Pages/Pages/SubPages/Collections.js +++ b/src/Admin/Pages/Pages/SubPages/Collections.js @@ -145,6 +145,7 @@ const Collections = () => { ); setCurrPage(0) HandleStateCircularProgress(null); + removeItemFromList(id); } }, (error) => { @@ -188,6 +189,22 @@ const Collections = () => { return Url("collections", "", currPage, "DESC") } + const removeItemFromList = (itemId) => { + let index = -1; + for (let i = 0; i < items.length; i++) { + const element = items[i]; + if (element.id === itemId) { + index = i + break + } + } + if(index !== -1) { + const cpyItems = [...items] + cpyItems.splice(index, 1) + setItems(cpyItems) + } + } + useEffect(() => { if (currPage === 0) setIsLoaded(false) @@ -251,6 +268,15 @@ const Collections = () => { }) } /> + <AlertDialog + open={openAlertDialog} + OnDelete={DeleteHandler} + deleteItem={deleteItem} + HandleClose={() => { + setOpenAlertDialog(false); + HandleStateCircularProgress(null); + }} + /> <Paper style={{ padding: "1em" }}> <Grid container spacing={3} direction="row" alignItems="center"> <Grid item xs={12}> @@ -388,6 +414,21 @@ const Collections = () => { { title: "Atualizado em", subtitle: DisplayDate(row.updated_at) + }, + { + title: "Deletar", + subtitle: + <Button + variant="contained" + color="secondary" + onClick={() => { + HandleStateAlertDialog(index); + HandleStateCircularProgress(index); + }} + startIcon={<DeleteIcon />} + > + Deletar + </Button> } ] } diff --git a/src/Admin/Pages/Pages/SubPages/Institutions.js b/src/Admin/Pages/Pages/SubPages/Institutions.js index d751db6ff8aa6e24643de023b9e993257ad193f8..7b9b45bd09f51232b235594be4a8cc6dd2381c23 100644 --- a/src/Admin/Pages/Pages/SubPages/Institutions.js +++ b/src/Admin/Pages/Pages/SubPages/Institutions.js @@ -173,6 +173,7 @@ const Institutions = () => { "#228B22" ); setCurrPage(0) + removeItemFromList(id); HandleStateCircularProgress(null); } }, @@ -183,6 +184,22 @@ const Institutions = () => { ) } + const removeItemFromList = (itemId) => { + let index = -1; + for (let i = 0; i < items.length; i++) { + const element = items[i]; + if (element.id === itemId) { + index = i + break + } + } + if (index !== -1) { + const cpyItems = [...items] + cpyItems.splice(index, 1) + setItems(cpyItems) + } + } + const buildUrl = () => { return Url("institutions", `"name" : "${search}", "description" : "${description}", "city" : "${city}", "country" : "${country}"`, currPage, "DESC") } @@ -300,6 +317,15 @@ const Institutions = () => { }) } /> + <AlertDialog + open={openAlertDialog} + OnDelete={DeleteHandler} + deleteItem={deleteItem} + HandleClose={() => { + setOpenAlertDialog(false); + HandleStateCircularProgress(null); + }} + /> {/************** Start of the header **************/} <Paper style={{ padding: "1em" }}> <Grid container spacing={3} direction="row" alignItems="center"> @@ -432,6 +458,21 @@ const Institutions = () => { title: "País", subtitle: row.country ? row.country : "Sem dado" }, + { + title: "Deletar", + subtitle: + <Button + variant="contained" + color="secondary" + onClick={() => { + HandleStateAlertDialog(index); + HandleStateCircularProgress(index); + }} + startIcon={<DeleteIcon />} + > + Deletar + </Button> + } ] } /> diff --git a/src/env.js b/src/env.js index b7359157e1c0e9d260976bbe2b2545a2e0ca51b0..82bf229b11fe78f3cb5ff8a58d096eec156cedf2 100644 --- a/src/env.js +++ b/src/env.js @@ -17,7 +17,7 @@ You should have received a copy of the GNU Affero General Public License along with Plataforma Integrada MEC. If not, see <http://www.gnu.org/licenses/>.*/ -var apiDomain = 'https://api.portalmec.c3sl.ufpr.br', +var apiDomain = 'https://api.portalmectest.c3sl.ufpr.br', apiVersion = 'v1', apiUrl = apiDomain + '/' + apiVersion;