From b731c80830209d1061009243fd53f2ccd81cac6d Mon Sep 17 00:00:00 2001 From: Alex Santos Date: Mon, 27 Jun 2022 10:55:07 -0300 Subject: [PATCH] update Header --- src/components/header/Header.tsx | 42 +++++++++++++++++++--- src/pages/administrative/clients/index.tsx | 29 ++++++++++++--- 2 files changed, 63 insertions(+), 8 deletions(-) diff --git a/src/components/header/Header.tsx b/src/components/header/Header.tsx index 1fba829..b17d841 100644 --- a/src/components/header/Header.tsx +++ b/src/components/header/Header.tsx @@ -6,6 +6,8 @@ import TextField from '@mui/material/TextField'; import { HeaderView } from './HeaderView' import { parseCookies } from 'nookies'; +import { GetServerSideProps } from 'next'; +import getAPIClient from '../../services/ssrApi'; function stringToColor(string: string) { let hash = 0; @@ -37,20 +39,21 @@ function stringAvatar(name: string) { interface headerInterface { name: string, admin?: boolean | undefined + logo?: string } -export default function Header({ name, admin }: headerInterface) { +export default function Header({ name, admin, logo }: headerInterface) { return (
- {/* { + { !admin? - + : null - } */} + }

olá, {name} @@ -61,3 +64,34 @@ export default function Header({ name, admin }: headerInterface) { ) } + +export const getServerSideProps: GetServerSideProps = async (ctx) => { + const apiClient = getAPIClient(ctx) + const { ['@smartAuth-token']: token } = parseCookies(ctx) + const { ['user-name']: userName } = parseCookies(ctx) + + let userData = []; + + await apiClient.get('/user').then(res => { + userData = res.data.data + }).catch(res => { + // console.log(res) + }) + + if (!token) { + return { + redirect: { + destination: '/', + permanent: false + } + } + } + + return { + props: { + userData, + userName + } + } +} + diff --git a/src/pages/administrative/clients/index.tsx b/src/pages/administrative/clients/index.tsx index 70b0b15..ae8490e 100644 --- a/src/pages/administrative/clients/index.tsx +++ b/src/pages/administrative/clients/index.tsx @@ -23,6 +23,7 @@ import getAPIClient from '../../../services/ssrApi' import FormData from 'form-data' import { InputUploadView } from '../../../components/inputUploadImg/inputUploadView' +import { FormControl, InputLabel, MenuItem, Select } from '@mui/material' const style = { position: 'absolute' as const, @@ -66,7 +67,7 @@ export default function clients({ clients, userName }) { const handleClose = () => setOpen(false) const [openModal, setOpenModal] = useState(false) - + const [nivelAcess, setnivelAcess] = useState(0); const [openSnackSuccess, setOpenSnackSuccess] = useState(false) const [openSnackError, setOpenSnackError] = useState(false) const [openSnackSuccessDelete, setOpenSnackSuccessDelete] = @@ -115,7 +116,7 @@ export default function clients({ clients, userName }) { formData.append('password_confirmation', password_confirmation) formData.append('client_id', client_id) formData.append('profile_picture', logo) - + formData.append('role', 0) api .post('/user', formData) .then((res) => { @@ -127,6 +128,7 @@ export default function clients({ clients, userName }) { setOpenSnackError(true) }) } + async function handleDeleteClient(id: any) { await id.map((client) => { api @@ -341,8 +343,27 @@ export default function clients({ clients, userName }) {

-
-
+ + +
+ + + Nivel de acesso + + +
+ setOpen(false)} />