From b7ea5538869efedb2e6fa87fc2b5fb8c3a016f2d Mon Sep 17 00:00:00 2001 From: Alex Santos Date: Fri, 17 Jun 2022 11:53:45 -0300 Subject: [PATCH] update Graph --- .../administrativeTables/FaqTable.tsx | 13 ++- src/components/modal/ConfirmModal.tsx | 4 +- src/pages/administrative/faq/index.tsx | 105 ++++++++++++++++-- .../administrative/notification/index.tsx | 7 +- src/pages/grossSavings.tsx | 39 +++++++ 5 files changed, 152 insertions(+), 16 deletions(-) diff --git a/src/components/administrativeTables/FaqTable.tsx b/src/components/administrativeTables/FaqTable.tsx index 0b5878c..e8bb8ce 100644 --- a/src/components/administrativeTables/FaqTable.tsx +++ b/src/components/administrativeTables/FaqTable.tsx @@ -17,7 +17,7 @@ import TableRow from '@mui/material/TableRow'; import TableSortLabel from '@mui/material/TableSortLabel'; import { visuallyHidden } from '@mui/utils'; import { GetServerSideProps } from 'next'; -import React, { useState } from 'react'; +import React, { useEffect, useState } from 'react'; import getAPIClient from '../../services/ssrApi'; import { ClientTableView, StyledStatus } from './ClientsTableView'; @@ -28,6 +28,11 @@ interface Data { status: string, } +interface FaqTableInterface{ + questionData: any, + onChange: any +} + function createData( question: 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('asc'); const [orderBy, setOrderBy] = useState('status'); const [selected, setSelected] = useState([]); @@ -229,6 +234,10 @@ export default function FaqTable({questionData}: any) { const isSelected = (name: string) => selected.indexOf(name) !== -1; + useEffect(() => { + onChange(selected) + }, [selected]) + // Avoid a layout jump when reaching the last page with empty rows. const emptyRows = page > 0 ? Math.max(0, (1 + page) * rowsPerPage - rows.length) : 0; diff --git a/src/components/modal/ConfirmModal.tsx b/src/components/modal/ConfirmModal.tsx index b38e561..6158dc2 100644 --- a/src/components/modal/ConfirmModal.tsx +++ b/src/components/modal/ConfirmModal.tsx @@ -12,8 +12,8 @@ const style = { top: '50%', left: '50%', transform: 'translate(-50%, -50%)', - width: '30%', - height: '30%', + width: 900, + height: 500, bgcolor: 'background.paper', border: '2px solid #254F7F', boxShadow: 24, diff --git a/src/pages/administrative/faq/index.tsx b/src/pages/administrative/faq/index.tsx index d1874ad..01d82b6 100644 --- a/src/pages/administrative/faq/index.tsx +++ b/src/pages/administrative/faq/index.tsx @@ -10,7 +10,10 @@ import Link from 'next/link' import { useRouter } from 'next/router' import React, { useEffect, useState } from 'react' 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 BasicButton from '../../../components/buttons/basicButton/BasicButton'; @@ -23,6 +26,7 @@ import getAPIClient from '../../../services/ssrApi'; import { GetServerSideProps } from 'next'; import { parseCookies } from 'nookies'; + const style = { position: 'absolute' as const, top: '50%', @@ -36,14 +40,69 @@ const style = { p: 4, }; +const Alert = React.forwardRef(function Alert( + props, + ref, +) { + return ; +}); + + type FaqInterface = { question: string; answer: string; } +export default function Sidebar({faqData} : any ) { -export default function Sidebar({faqData}) { + const [openModalInativar, setOpenModalInativar] = useState(false) + const [openSnackSuccess, setOpenSnackSuccess] = useState(false); + const [openSnackError, setOpenSnackError] = useState(false); + const [openSnackSuccessDelete, setOpenSnackSuccessDelete] = useState(false); + const [openSnackErrorDelete, setOpenSnackErrorDelete] = useState(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({ + question: '', + answer : '', + + }) + + const [selectedfaq, setSelectedfaq] = useState([]) + async function handleRegisterNewFaq({question, answer}: FaqInterface) { await api.post('/faq', { "question": question, @@ -52,10 +111,7 @@ export default function Sidebar({faqData}) { }).then(res => console.log(res.data)) } - const [faq, setFaq] = useState({ - question: '', - answer: '', - }) + const [open, setOpen] = React.useState(false); @@ -69,9 +125,32 @@ export default function Sidebar({faqData}) { + + + Notificação cadastrada com sucesso! + + + + + Notificação não cadastrada! + + + + + + notificação excluida com sucesso! + + + + + Notificação não excluida! + + +
- + +
- + setSelectedfaq(value)}/> + + {setOpenModalInativar(value)}}> + + + handleDeleteNotification(selectedfaq)}/> + setOpenModalInativar(false)}/> + + @@ -115,7 +202,7 @@ export const getServerSideProps: GetServerSideProps = async (ctx) => { await apiClient.get('/faq').then(res => { - faqData = res.data + faqData = res.data.data }).catch(res => { console.log(res) }) diff --git a/src/pages/administrative/notification/index.tsx b/src/pages/administrative/notification/index.tsx index dc142d6..aa7573b 100644 --- a/src/pages/administrative/notification/index.tsx +++ b/src/pages/administrative/notification/index.tsx @@ -29,7 +29,7 @@ import MuiAlert, { AlertProps } from '@mui/material/Alert'; import BasicButton from '../../../components/buttons/basicButton/BasicButton'; import { ConfirmModalView } from '../../../styles/layouts/modals/confirmModalView'; import ConfirmModal from '../../../components/modal/ConfirmModal'; -import { JsxElement } from 'typescript'; + const style = { position: 'absolute' as const, @@ -61,6 +61,7 @@ interface NotificationInterface { users: object[] } +// teste export default function notification({clients, notifications}) { const [notification, setNotification] = useState({ @@ -127,7 +128,7 @@ export default function notification({clients, notifications}) { - notificação cadastrada com sucesso! + Notificação cadastrada com sucesso! @@ -257,7 +258,7 @@ export const getServerSideProps: GetServerSideProps = async (ctx) => { }) await apiClient.get('/notification').then(res => { - notifications = res.data + notifications = res.data.data }).catch(res => { console.log(res) }) diff --git a/src/pages/grossSavings.tsx b/src/pages/grossSavings.tsx index a8c2985..ac461e7 100644 --- a/src/pages/grossSavings.tsx +++ b/src/pages/grossSavings.tsx @@ -1,3 +1,4 @@ +import { GetServerSideProps } from 'next' import Head from 'next/head' import React from 'react' @@ -6,6 +7,7 @@ import { SingleBar } from '../components/graph/SingleBar' import Header from '../components/header/Header' import PageTitle from '../components/pageTitle/PageTitle' import { dataEconomiaBruta } from '../services/economiaBruta' +import getAPIClient from '../services/ssrApi' import { GrossSavingsView } from '../styles/layouts/economy/grossSavings/GrossSavings' @@ -23,3 +25,40 @@ export default function GrossSavings() { ) } +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 + } + } +}