Skip to content

Commit

Permalink
producer dashboard - first draft
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminpochat committed Aug 6, 2024
1 parent 75ef6e6 commit 9a828ab
Show file tree
Hide file tree
Showing 17 changed files with 289 additions and 198 deletions.
5 changes: 5 additions & 0 deletions frontend/app/src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
cursor: pointer;
}

.link {
color: unset;
text-decoration: none;
}

.lot {
border-top: 1px solid lightgrey;
display: flex;
Expand Down
95 changes: 8 additions & 87 deletions frontend/app/src/App.js
Original file line number Diff line number Diff line change
@@ -1,117 +1,38 @@
import { ThemeProvider } from '@mui/material';
import { createTheme } from '@mui/material/styles';
import { frFR } from '@mui/material/locale';
import { LocalizationProvider } from "@mui/x-date-pickers"
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs'

import { ReactKeycloakProvider } from '@react-keycloak/web'
import Keycloak from 'keycloak-js'
import { ReactKeycloakProvider } from '@react-keycloak/web'

import { CookiesProvider } from 'react-cookie';
import { RouterProvider } from "react-router-dom";

import { createBrowserRouter, RouterProvider } from "react-router-dom";

import CustomerLayout from './layouts/customer/CustomerLayout.tsx';
import CustomerOrderView from './layouts/customer/PaymentLayout.tsx'
import { RouterFactory } from './layouts/RouterFactory.tsx';

import './App.css';
import PaymentLayout from './layouts/customer/PaymentLayout.tsx';
import Dashboard from './domains/dashboard/views/Dashboard.tsx';
import ProductionController from './domains/production/ProductionController.tsx';
import SaleController from './domains/sale/SaleController.tsx';
import CustomerController from './domains/customer/CustomerController.tsx';
import ProducerController from './domains/producer/ProducerController.tsx';
import { ThemeFactory } from './layouts/ThemeFactory.ts';


function App() {

const keycloakClient = new Keycloak(window.location.origin + '/config/keycloak.json')
const routerFactory = new RouterFactory()
const themeFactory = new ThemeFactory()

const keycloakInitOptions = {
checkLoginIframe: false,
onLoad: 'check-sso',
silentCheckSsoRedirectUri: window.location.origin + '/silent-check-sso.html'
}

const theme = createTheme({
palette: {
//mode: 'dark',
primary: {
main: '#556b2f',
}
},
typography: {
h1: {
fontFamily: 'Acme',
},
h2: {
fontFamily: 'Acme',
},
h3: {
fontFamily: 'Acme',
},
h4: {
fontFamily: 'Acme',
},
h5: {
fontFamily: 'Acme',
},
h6: {
fontFamily: 'Acme',
},
subtitle1: {
fontWeight: 'bold'
}
}
}, frFR);

const router = createBrowserRouter([
{
path: "/",
element: getLayoutWrapper(),
},
{
path: "/dashboard",
element: <Dashboard/>
},
{
path: "/productions",
element: <ProductionController/>
},
{
path: "/sales",
element: <SaleController/>
},
{
path: "/customers",
element: <CustomerController/>
},
{
path: "/account",
element: <ProducerController/>
},
{
path: "/orders/:orderId/payment",
element: <PaymentLayout/>
}
]);

function getLayoutWrapper(mainContent) {
if(process.env.REACT_APP_MODE === 'CUSTOMER') {
return <CustomerLayout/>
}
if(process.env.REACT_APP_MODE === 'PRODUCER') {
return <Dashboard/>
}
return <div>Configuration du mode client ou producteur absent ou non reconnu</div>
}

return (
<CookiesProvider>
<ReactKeycloakProvider authClient={keycloakClient} initOptions={keycloakInitOptions}>
<ThemeProvider theme={theme}>
<ThemeProvider theme={themeFactory.createTheme()}>
<LocalizationProvider dateAdapter={AdapterDayjs} adapterLocale="fr">
<RouterProvider router={router} />
<RouterProvider router={routerFactory.getRouter()} />
</LocalizationProvider>
</ThemeProvider>
</ReactKeycloakProvider>
Expand Down
2 changes: 1 addition & 1 deletion frontend/app/src/domains/customer/CustomerController.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default function CustomerController() {
producerService.loadProducer(setProducer)
})

return <AuthenticatedLayout>{getContent()}</AuthenticatedLayout>
return <>{getContent()}</>

function getContent() {
if(producer) {
Expand Down
4 changes: 2 additions & 2 deletions frontend/app/src/domains/dashboard/views/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import DashboardProductions from '../components/DashboardProductions.tsx'
import DashboardSales from '../components/DashboardSales.tsx'

function Dashboard() {
return <AuthenticatedLayout>
return <>
<Typography variant="h6">Tableau de bord</Typography>
<div className="dashboard-container">
<div className="dashboard-item"><DashboardAccount/></div>
<div className="dashboard-item">Mes derniers versements</div>
<div className="dashboard-item"><DashboardProductions/></div>
<div className="dashboard-item"><DashboardSales/></div>
</div>
</AuthenticatedLayout>
</>
}

export default Dashboard
4 changes: 2 additions & 2 deletions frontend/app/src/domains/producer/ProducerController.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ function ProducerController() {
})
})

return <AuthenticatedLayout>
return <>
<Typography variant="h6">Gestion du compte</Typography>
{displayStripeAccount()}
</AuthenticatedLayout>
</>

function loadStripeAccount(producerId: number) {
apiInvoker.callApiAuthenticatedly(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default function ProductionController({producer: producer}) {
const [currentAction, setCurrentAction] = useState(PRODUCTIONS_LIST)
const [context, setContext] = useState(undefined)

return <AuthenticatedLayout>{getContent()}</AuthenticatedLayout>
return <>{getContent()}</>

function getContent() {
switch (currentAction) {
Expand Down
2 changes: 1 addition & 1 deletion frontend/app/src/domains/sale/SaleController.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default function SaleController() {
producerService.loadProducer(setProducer)
})

return <AuthenticatedLayout>{getCurrentView()}</AuthenticatedLayout>
return <>{getCurrentView()}</>

function getCurrentView() {
if(producer) {
Expand Down
6 changes: 6 additions & 0 deletions frontend/app/src/layouts/ErrorLayout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Typography } from "@mui/material";
import React from "react";

export function ErrorLayout({message: message}) {
return <Typography>{message}</Typography>
}
26 changes: 26 additions & 0 deletions frontend/app/src/layouts/RouterFactory.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { createBrowserRouter } from "react-router-dom"
import { CustomerRouterFactory } from "./customer/CustomerRouterFactory.tsx"
import { ProducerRouterFactory } from "./producer/ProducerRouterFactory.tsx"
import React from "react"
import { ErrorLayout } from "./ErrorLayout.tsx"

export class RouterFactory {

producerRouterFactory: ProducerRouterFactory = new ProducerRouterFactory()
customerRouterFactory: CustomerRouterFactory = new CustomerRouterFactory()

getRouter() {
if(process.env.REACT_APP_MODE === 'CUSTOMER') {
return this.customerRouterFactory.getRouter()
}
if(process.env.REACT_APP_MODE === 'PRODUCER') {
return this.producerRouterFactory.getRouter()
}
return createBrowserRouter([
{
path: "/",
element: <ErrorLayout message='Configuration du mode client ou producteur absent ou non reconnu'/>
}
])
}
}
38 changes: 38 additions & 0 deletions frontend/app/src/layouts/ThemeFactory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { createTheme } from "@mui/material";
import { frFR } from '@mui/material/locale';

export class ThemeFactory {
createTheme() {
return createTheme({
palette: {
//mode: 'dark',
primary: {
main: '#556b2f',
}
},
typography: {
h1: {
fontFamily: 'Acme',
},
h2: {
fontFamily: 'Acme',
},
h3: {
fontFamily: 'Acme',
},
h4: {
fontFamily: 'Acme',
},
h5: {
fontFamily: 'Acme',
},
h6: {
fontFamily: 'Acme',
},
subtitle1: {
fontWeight: 'bold'
}
}
}, frFR);
}
}
11 changes: 7 additions & 4 deletions frontend/app/src/layouts/customer/CustomerLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import CustomerCreationForm from '../../domains/customer/views/CustomerCreationF
import Welcome from '../../domains/welcome/Welcome.tsx'
import { Login, Logout } from '@mui/icons-material'
import NotAuthorizedForProducers from '../../authentication/views/NotAuthorizedForProducers.tsx'
import { Outlet, useNavigate } from 'react-router-dom'


export default function CustomerLayout() {
Expand All @@ -33,6 +34,7 @@ export default function CustomerLayout() {
const [context, setContext] = useState(undefined)
const [cookies, setCookie, removeCookie] = useCookies(['pendingOrder']);
const [customer, setCustomer] = useState<Customer>(undefined)
const navigate = useNavigate()

useEffect(() => {
if (initialized) {
Expand Down Expand Up @@ -65,7 +67,7 @@ export default function CustomerLayout() {
setCustomer(customer)
}
}

/*
function displayMainContent() {
if(authenticationService.isAuthenticated() && customer && !customer.id) {
return <CustomerCreationForm customer={customer} returnCallback={newCustomer => setCustomer(newCustomer)}></CustomerCreationForm>
Expand All @@ -79,10 +81,11 @@ export default function CustomerLayout() {
}
}

*/
function createOrder(sale: Sale) {
setContext(sale)
setMainContent(ORDER_CREATION)
/*setMainContent(ORDER_CREATION)*/
navigate('/order/creation')
}

function displayAuthenticationButton(): React.ReactNode {
Expand Down Expand Up @@ -115,7 +118,7 @@ export default function CustomerLayout() {
{displayAuthenticationButton()}
</Toolbar>
</AppBar>
{displayMainContent()}
<Outlet/>
</Box>
)
}
38 changes: 38 additions & 0 deletions frontend/app/src/layouts/customer/CustomerRouterFactory.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import React from "react";

import { createBrowserRouter } from "react-router-dom";

import PaymentLayout from "./PaymentLayout.tsx";
import CustomerLayout from "./CustomerLayout.tsx";
import CustomerOrderForm from "../../domains/sale/views/CustomerOrderForm.tsx";
import NotAuthorizedForProducers from "../../authentication/views/NotAuthorizedForProducers.tsx";
import Welcome from "../../domains/welcome/Welcome.tsx";

export class CustomerRouterFactory {
getRouter() {
return createBrowserRouter([
{
path: "/",
element: <CustomerLayout/>,
children: [
{
path: "/welcome",
element: <Welcome/>
},
{
path: "/order/creation",
element: <CustomerOrderForm/>
},
{
path: "/orders/:orderId/payment",
element: <PaymentLayout/>
}
]
},
{
path: "/unauthorized",
element: <NotAuthorizedForProducers/>
}
])
}
}
1 change: 1 addition & 0 deletions frontend/app/src/layouts/producer/AnonymousLayout.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { styled } from '@mui/material/styles';
import { AppBar, Box, Typography, CssBaseline, Toolbar, Grid, Paper, Button } from "@mui/material";
import { useKeycloak } from '@react-keycloak/web'
import React from 'react';

function AnonymousLayout() {

Expand Down
9 changes: 4 additions & 5 deletions frontend/app/src/layouts/producer/AuthenticatedLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ import {Close, Logout, Menu} from '@mui/icons-material'
import { ApiInvoker } from '../../api/ApiInvoker.ts'

import Producer from 'viandeendirect_eu/dist/model/Producer.js';
import SideMenu from './SideMenu.js'
import SideMenu from './SideMenu.jsx'
import { AuthenticationService } from '../../authentication/service/AuthenticationService.ts';
import NotAuthorizedForCustomers from '../../authentication/views/NotAuthorizedForCustomers.tsx';
import { ProducerService } from '../../domains/commons/service/ProducerService.ts';
import { Outlet } from 'react-router-dom';


function AuthenticatedLayout(props) {
export default function AuthenticatedLayout(props) {
const { keycloak, initialized } = useKeycloak()
const [sideMenuOpen, setSideMenuOpen] = useState(false)
const [producer, setProducer] = useState<Producer>()
Expand Down Expand Up @@ -87,10 +88,8 @@ function AuthenticatedLayout(props) {
sx={{ flexGrow: 1, p: 3 }}
width={'100%'}>
<Toolbar />
{props.children}
<Outlet/>
</Box>
</Box>
)
}

export default AuthenticatedLayout
Loading

0 comments on commit 9a828ab

Please sign in to comment.