update Graph
This commit is contained in:
parent
e7d49ecf4d
commit
b7ea553886
@ -17,7 +17,7 @@ import TableRow from '@mui/material/TableRow';
|
|||||||
import TableSortLabel from '@mui/material/TableSortLabel';
|
import TableSortLabel from '@mui/material/TableSortLabel';
|
||||||
import { visuallyHidden } from '@mui/utils';
|
import { visuallyHidden } from '@mui/utils';
|
||||||
import { GetServerSideProps } from 'next';
|
import { GetServerSideProps } from 'next';
|
||||||
import React, { useState } from 'react';
|
import React, { useEffect, useState } from 'react';
|
||||||
import getAPIClient from '../../services/ssrApi';
|
import getAPIClient from '../../services/ssrApi';
|
||||||
|
|
||||||
import { ClientTableView, StyledStatus } from './ClientsTableView';
|
import { ClientTableView, StyledStatus } from './ClientsTableView';
|
||||||
@ -28,6 +28,11 @@ interface Data {
|
|||||||
status: string,
|
status: string,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface FaqTableInterface{
|
||||||
|
questionData: any,
|
||||||
|
onChange: any
|
||||||
|
}
|
||||||
|
|
||||||
function createData(
|
function createData(
|
||||||
question: string,
|
question: string,
|
||||||
answer: string,
|
answer: string,
|
||||||
@ -170,7 +175,7 @@ function EnhancedTableHead(props: EnhancedTableProps) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function FaqTable({questionData}: any) {
|
export default function FaqTable({questionData, onChange}: FaqTableInterface) {
|
||||||
const [order, setOrder] = useState<Order>('asc');
|
const [order, setOrder] = useState<Order>('asc');
|
||||||
const [orderBy, setOrderBy] = useState<keyof Data | string>('status');
|
const [orderBy, setOrderBy] = useState<keyof Data | string>('status');
|
||||||
const [selected, setSelected] = useState<readonly string[]>([]);
|
const [selected, setSelected] = useState<readonly string[]>([]);
|
||||||
@ -229,6 +234,10 @@ export default function FaqTable({questionData}: any) {
|
|||||||
|
|
||||||
const isSelected = (name: string) => selected.indexOf(name) !== -1;
|
const isSelected = (name: string) => selected.indexOf(name) !== -1;
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
onChange(selected)
|
||||||
|
}, [selected])
|
||||||
|
|
||||||
// Avoid a layout jump when reaching the last page with empty rows.
|
// Avoid a layout jump when reaching the last page with empty rows.
|
||||||
const emptyRows =
|
const emptyRows =
|
||||||
page > 0 ? Math.max(0, (1 + page) * rowsPerPage - rows.length) : 0;
|
page > 0 ? Math.max(0, (1 + page) * rowsPerPage - rows.length) : 0;
|
||||||
|
|||||||
@ -12,8 +12,8 @@ const style = {
|
|||||||
top: '50%',
|
top: '50%',
|
||||||
left: '50%',
|
left: '50%',
|
||||||
transform: 'translate(-50%, -50%)',
|
transform: 'translate(-50%, -50%)',
|
||||||
width: '30%',
|
width: 900,
|
||||||
height: '30%',
|
height: 500,
|
||||||
bgcolor: 'background.paper',
|
bgcolor: 'background.paper',
|
||||||
border: '2px solid #254F7F',
|
border: '2px solid #254F7F',
|
||||||
boxShadow: 24,
|
boxShadow: 24,
|
||||||
|
|||||||
@ -10,7 +10,10 @@ import Link from 'next/link'
|
|||||||
import { useRouter } from 'next/router'
|
import { useRouter } from 'next/router'
|
||||||
import React, { useEffect, useState } from 'react'
|
import React, { useEffect, useState } from 'react'
|
||||||
import { api } from '../../../services/api';
|
import { api } from '../../../services/api';
|
||||||
|
import ConfirmModal from '../../../components/modal/ConfirmModal';
|
||||||
|
import { ConfirmModalView } from '../../../styles/layouts/modals/confirmModalView';
|
||||||
|
import Snackbar from '@mui/material/Snackbar';
|
||||||
|
import MuiAlert, { AlertProps } from '@mui/material/Alert';
|
||||||
|
|
||||||
import FaqTable from '../../../components/administrativeTables/FaqTable';
|
import FaqTable from '../../../components/administrativeTables/FaqTable';
|
||||||
import BasicButton from '../../../components/buttons/basicButton/BasicButton';
|
import BasicButton from '../../../components/buttons/basicButton/BasicButton';
|
||||||
@ -23,6 +26,7 @@ import getAPIClient from '../../../services/ssrApi';
|
|||||||
import { GetServerSideProps } from 'next';
|
import { GetServerSideProps } from 'next';
|
||||||
import { parseCookies } from 'nookies';
|
import { parseCookies } from 'nookies';
|
||||||
|
|
||||||
|
|
||||||
const style = {
|
const style = {
|
||||||
position: 'absolute' as const,
|
position: 'absolute' as const,
|
||||||
top: '50%',
|
top: '50%',
|
||||||
@ -36,14 +40,69 @@ const style = {
|
|||||||
p: 4,
|
p: 4,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const Alert = React.forwardRef<HTMLDivElement, AlertProps>(function Alert(
|
||||||
|
props,
|
||||||
|
ref,
|
||||||
|
) {
|
||||||
|
return <MuiAlert elevation={6} ref={ref} variant="filled" {...props} />;
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
type FaqInterface = {
|
type FaqInterface = {
|
||||||
question: string;
|
question: string;
|
||||||
answer: string;
|
answer: string;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
export default function Sidebar({faqData} : any ) {
|
||||||
|
|
||||||
|
|
||||||
export default function Sidebar({faqData}) {
|
const [openModalInativar, setOpenModalInativar] = useState<boolean>(false)
|
||||||
|
const [openSnackSuccess, setOpenSnackSuccess] = useState<boolean>(false);
|
||||||
|
const [openSnackError, setOpenSnackError] = useState<boolean>(false);
|
||||||
|
const [openSnackSuccessDelete, setOpenSnackSuccessDelete] = useState<boolean>(false);
|
||||||
|
const [openSnackErrorDelete, setOpenSnackErrorDelete] = useState<boolean>(false);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
const handleCloseSnack = (event?: React.SyntheticEvent | Event, reason?: string) => {
|
||||||
|
if (reason === 'clickaway') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setOpenSnackError(false);
|
||||||
|
setOpenSnackSuccess(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
const handleCloseSnackDelete = (event?: React.SyntheticEvent | Event, reason?: string) => {
|
||||||
|
if (reason === 'clickaway') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setOpenSnackErrorDelete(false);
|
||||||
|
setOpenSnackSuccessDelete(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
async function handleDeleteNotification(id: any) {
|
||||||
|
await id.map((value) => {
|
||||||
|
api.delete(`/faq/${value}`).then(res => {
|
||||||
|
setOpenSnackSuccessDelete(true)
|
||||||
|
setOpenModalInativar(false)
|
||||||
|
window.location.reload()
|
||||||
|
}).catch(res => setOpenSnackErrorDelete(true))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
const [faq, setFaq] = useState<FaqInterface>({
|
||||||
|
question: '',
|
||||||
|
answer : '',
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
const [selectedfaq, setSelectedfaq] = useState([])
|
||||||
|
|
||||||
async function handleRegisterNewFaq({question, answer}: FaqInterface) {
|
async function handleRegisterNewFaq({question, answer}: FaqInterface) {
|
||||||
await api.post('/faq', {
|
await api.post('/faq', {
|
||||||
"question": question,
|
"question": question,
|
||||||
@ -52,10 +111,7 @@ export default function Sidebar({faqData}) {
|
|||||||
}).then(res => console.log(res.data))
|
}).then(res => console.log(res.data))
|
||||||
}
|
}
|
||||||
|
|
||||||
const [faq, setFaq] = useState<FaqInterface>({
|
|
||||||
question: '',
|
|
||||||
answer: '',
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
const [open, setOpen] = React.useState(false);
|
const [open, setOpen] = React.useState(false);
|
||||||
@ -69,9 +125,32 @@ export default function Sidebar({faqData}) {
|
|||||||
|
|
||||||
<PageTitle title='Perguntas Frequentes' subtitle='Perguntas Frequentes'/>
|
<PageTitle title='Perguntas Frequentes' subtitle='Perguntas Frequentes'/>
|
||||||
|
|
||||||
|
<Snackbar open={openSnackSuccess} autoHideDuration={4000} onClose={handleCloseSnack}>
|
||||||
|
<Alert onClose={handleCloseSnack} severity="success" sx={{ width: '100%' }}>
|
||||||
|
Notificação cadastrada com sucesso!
|
||||||
|
</Alert>
|
||||||
|
</Snackbar>
|
||||||
|
<Snackbar open={openSnackError} autoHideDuration={4000} onClose={handleCloseSnack}>
|
||||||
|
<Alert onClose={handleCloseSnack} severity="error" sx={{ width: '100%' }}>
|
||||||
|
Notificação não cadastrada!
|
||||||
|
</Alert>
|
||||||
|
</Snackbar>
|
||||||
|
|
||||||
|
<Snackbar open={openSnackSuccessDelete} autoHideDuration={4000} onClose={handleCloseSnackDelete}>
|
||||||
|
<Alert onClose={handleCloseSnackDelete} severity="success" sx={{ width: '100%' }}>
|
||||||
|
notificação excluida com sucesso!
|
||||||
|
</Alert>
|
||||||
|
</Snackbar>
|
||||||
|
<Snackbar open={openSnackErrorDelete} autoHideDuration={4000} onClose={handleCloseSnackDelete}>
|
||||||
|
<Alert onClose={handleCloseSnackDelete} severity="error" sx={{ width: '100%' }}>
|
||||||
|
Notificação não excluida!
|
||||||
|
</Alert>
|
||||||
|
</Snackbar>
|
||||||
|
|
||||||
<div className='buttons'>
|
<div className='buttons'>
|
||||||
<button className='btn2' value="Refresh Page"onClick={handleOpen} >Adicionar</button>
|
<button className='btn2' value="Refresh Page"onClick={handleOpen} >Adicionar</button>
|
||||||
<button className='btn1' onClick={handleOpen}>Inativar</button>
|
<button className='btn1' onClick={() => setOpenModalInativar(true)}>Inativar</button>
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<Modal
|
<Modal
|
||||||
@ -100,7 +179,15 @@ export default function Sidebar({faqData}) {
|
|||||||
</Box>
|
</Box>
|
||||||
|
|
||||||
</Modal>
|
</Modal>
|
||||||
<FaqTable questionData={faqData}/>
|
<FaqTable questionData={faqData} onChange={value => setSelectedfaq(value)}/>
|
||||||
|
|
||||||
|
<ConfirmModal open={openModalInativar} handleIsClose={(value) => {setOpenModalInativar(value)}}>
|
||||||
|
<PageTitle title='Excluir notificação' subtitle='deseja realmente excluir as notificações selecionadas?'/>
|
||||||
|
<ConfirmModalView>
|
||||||
|
<BasicButton title='Confirmar' onClick={() => handleDeleteNotification(selectedfaq)}/>
|
||||||
|
<BasicButton title='Cancelar' onClick={() => setOpenModalInativar(false)}/>
|
||||||
|
</ConfirmModalView>
|
||||||
|
</ConfirmModal>
|
||||||
|
|
||||||
</FaqView>
|
</FaqView>
|
||||||
</>
|
</>
|
||||||
@ -115,7 +202,7 @@ export const getServerSideProps: GetServerSideProps = async (ctx) => {
|
|||||||
|
|
||||||
|
|
||||||
await apiClient.get('/faq').then(res => {
|
await apiClient.get('/faq').then(res => {
|
||||||
faqData = res.data
|
faqData = res.data.data
|
||||||
}).catch(res => {
|
}).catch(res => {
|
||||||
console.log(res)
|
console.log(res)
|
||||||
})
|
})
|
||||||
|
|||||||
@ -29,7 +29,7 @@ import MuiAlert, { AlertProps } from '@mui/material/Alert';
|
|||||||
import BasicButton from '../../../components/buttons/basicButton/BasicButton';
|
import BasicButton from '../../../components/buttons/basicButton/BasicButton';
|
||||||
import { ConfirmModalView } from '../../../styles/layouts/modals/confirmModalView';
|
import { ConfirmModalView } from '../../../styles/layouts/modals/confirmModalView';
|
||||||
import ConfirmModal from '../../../components/modal/ConfirmModal';
|
import ConfirmModal from '../../../components/modal/ConfirmModal';
|
||||||
import { JsxElement } from 'typescript';
|
|
||||||
|
|
||||||
const style = {
|
const style = {
|
||||||
position: 'absolute' as const,
|
position: 'absolute' as const,
|
||||||
@ -61,6 +61,7 @@ interface NotificationInterface {
|
|||||||
users: object[]
|
users: object[]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// teste
|
||||||
export default function notification({clients, notifications}) {
|
export default function notification({clients, notifications}) {
|
||||||
|
|
||||||
const [notification, setNotification] = useState<NotificationInterface>({
|
const [notification, setNotification] = useState<NotificationInterface>({
|
||||||
@ -127,7 +128,7 @@ export default function notification({clients, notifications}) {
|
|||||||
|
|
||||||
<Snackbar open={openSnackSuccess} autoHideDuration={4000} onClose={handleCloseSnack}>
|
<Snackbar open={openSnackSuccess} autoHideDuration={4000} onClose={handleCloseSnack}>
|
||||||
<Alert onClose={handleCloseSnack} severity="success" sx={{ width: '100%' }}>
|
<Alert onClose={handleCloseSnack} severity="success" sx={{ width: '100%' }}>
|
||||||
notificação cadastrada com sucesso!
|
Notificação cadastrada com sucesso!
|
||||||
</Alert>
|
</Alert>
|
||||||
</Snackbar>
|
</Snackbar>
|
||||||
<Snackbar open={openSnackError} autoHideDuration={4000} onClose={handleCloseSnack}>
|
<Snackbar open={openSnackError} autoHideDuration={4000} onClose={handleCloseSnack}>
|
||||||
@ -257,7 +258,7 @@ export const getServerSideProps: GetServerSideProps = async (ctx) => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
await apiClient.get('/notification').then(res => {
|
await apiClient.get('/notification').then(res => {
|
||||||
notifications = res.data
|
notifications = res.data.data
|
||||||
}).catch(res => {
|
}).catch(res => {
|
||||||
console.log(res)
|
console.log(res)
|
||||||
})
|
})
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
import { GetServerSideProps } from 'next'
|
||||||
import Head from 'next/head'
|
import Head from 'next/head'
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
|
|
||||||
@ -6,6 +7,7 @@ import { SingleBar } from '../components/graph/SingleBar'
|
|||||||
import Header from '../components/header/Header'
|
import Header from '../components/header/Header'
|
||||||
import PageTitle from '../components/pageTitle/PageTitle'
|
import PageTitle from '../components/pageTitle/PageTitle'
|
||||||
import { dataEconomiaBruta } from '../services/economiaBruta'
|
import { dataEconomiaBruta } from '../services/economiaBruta'
|
||||||
|
import getAPIClient from '../services/ssrApi'
|
||||||
|
|
||||||
import { GrossSavingsView } from '../styles/layouts/economy/grossSavings/GrossSavings'
|
import { GrossSavingsView } from '../styles/layouts/economy/grossSavings/GrossSavings'
|
||||||
|
|
||||||
@ -23,3 +25,40 @@ export default function GrossSavings() {
|
|||||||
</GrossSavingsView>
|
</GrossSavingsView>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
export const getServerSideProps: GetServerSideProps = async (ctx) => {
|
||||||
|
const apiClient = getAPIClient(ctx)
|
||||||
|
const { ['@smartAuth-token']: token } = parseCookies(ctx)
|
||||||
|
|
||||||
|
let clients = [];
|
||||||
|
let notifications = [];
|
||||||
|
|
||||||
|
await apiClient.get('/user').then(res => {
|
||||||
|
clients = res.data
|
||||||
|
}).catch(res => {
|
||||||
|
console.log(res)
|
||||||
|
})
|
||||||
|
|
||||||
|
await apiClient.get('/economy/grossAnnual').then(res => {
|
||||||
|
grossSaving = res.data
|
||||||
|
grossSaving.map(value)
|
||||||
|
|
||||||
|
}).catch(res => {
|
||||||
|
console.log(res)
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!token) {
|
||||||
|
return {
|
||||||
|
redirect: {
|
||||||
|
destination: '/',
|
||||||
|
permanent: false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
props: {
|
||||||
|
clients,
|
||||||
|
grossSaving
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user