Skip to content

Commit

Permalink
load sales for customer layout
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminpochat committed Jan 12, 2024
1 parent daa73e7 commit 167e894
Show file tree
Hide file tree
Showing 17 changed files with 146 additions and 94 deletions.
4 changes: 2 additions & 2 deletions frontend/app/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ReactKeycloakProvider } from '@react-keycloak/web'
import Keycloak from 'keycloak-js'

import ProducerLayoutWrapper from './layouts/producer/LayoutWrapper';
import CustomerLayoutWrapper from './layouts/customer/LayoutWrapper';
import CustomerLayout from './layouts/customer/CustomerLayout';

import './App.css';

Expand Down Expand Up @@ -55,7 +55,7 @@ function App() {

function getLayoutWrapper() {
if(process.env.REACT_APP_MODE === 'CUSTOMER') {
return <CustomerLayoutWrapper/>
return <CustomerLayout/>
}
if(process.env.REACT_APP_MODE === 'PRODUCER') {
return <ProducerLayoutWrapper/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import ApiClient from 'viandeendirect_eu/dist/ApiClient'
import DefaultApi from 'viandeendirect_eu/dist/api/DefaultApi'
import { MockApi } from './mock/MockApi.ts'

export class AuthenticatedApiBuilder {
export class ApiBuilder {

backendUrl = undefined

Expand Down Expand Up @@ -32,6 +32,14 @@ export class AuthenticatedApiBuilder {
}
}

async getAnonymousApi() {
if(process.env.REACT_APP_MOCK_API) {
return new MockApi()
} else {
return new DefaultApi(ApiClient.instance)
}
}

/**
*
* @param {*} apiFunction
Expand All @@ -49,4 +57,8 @@ export class AuthenticatedApiBuilder {
})
}
}

invokeAnonymousApi(apiFunction) {
apiFunction()
}
}
8 changes: 4 additions & 4 deletions frontend/app/src/api/mock/MockApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,23 @@ export class MockApi {
}

getPackageTemplates(callback) {
callback(this.mockApiProductions.getPackageTemplates())
callback(undefined, this.mockApiProductions.getPackageTemplates())
}

getAddresses(callback) {
callback(this.mockApiAddresses.getAddresses())
callback(undefined, this.mockApiAddresses.getAddresses())
}

getCustomers(callback) {
callback(this.mockApiCustomers.getCustomers())
callback(undefined, this.mockApiCustomers.getCustomers())
}

getCutomer(customer, callback){
callback(undefined, this.mockApiCustomers.createCustomer(customer))
}

getSales(callback) {
callback(this.mockApiSales.getSales())
callback(undefined, this.mockApiSales.getSales())
}

getSaleOrders(options, callback) {
Expand Down
8 changes: 4 additions & 4 deletions frontend/app/src/domains/customer/views/CustomersList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@ import { Typography } from "@mui/material"
import { DataGrid, GridRowsProp, GridColDef, GridToolbar } from '@mui/x-data-grid';

import { useKeycloak } from '@react-keycloak/web'
import { AuthenticatedApiBuilder } from '../../../api/AuthenticatedApiBuilder'
import { ApiBuilder } from '../../../api/ApiBuilder.ts'

export default function CustomersList() {

const [customers, setCustomers] = useState([])
const { keycloak, initialized } = useKeycloak()
const authenticatedApiBuilder = new AuthenticatedApiBuilder()
const apiBuilder = new ApiBuilder()

useEffect(() => {
loadCustomers()
}, [keycloak])

function loadCustomers() {
authenticatedApiBuilder.getAuthenticatedApi(keycloak).then(api => {
authenticatedApiBuilder.invokeAuthenticatedApi(() => {
apiBuilder.getAuthenticatedApi(keycloak).then(api => {
apiBuilder.invokeAuthenticatedApi(() => {
api.getCustomers((error, data, response) => {
if (error) {
console.error(error)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import { useEffect, useState } from 'react';
import { useKeycloak } from '@react-keycloak/web'
import { Button, Card, CardActions, CardContent, Typography } from "@mui/material"
import { AuthenticatedApiBuilder } from '../../../api/AuthenticatedApiBuilder'
import { ApiBuilder } from '../../../api/ApiBuilder.ts'
import dayjs from 'dayjs'

export default function BeefProductionCard({
Expand All @@ -12,11 +12,11 @@ export default function BeefProductionCard({

const [beefProduction, setBeefProduction] = useState(production)
const { keycloak, initialized } = useKeycloak()
const authenticatedApiBuilder = new AuthenticatedApiBuilder()
const apiBuilder = new ApiBuilder()

useEffect(() => {
authenticatedApiBuilder.getAuthenticatedApi(keycloak).then(api => {
authenticatedApiBuilder.invokeAuthenticatedApi(() => {
apiBuilder.getAuthenticatedApi(keycloak).then(api => {
apiBuilder.invokeAuthenticatedApi(() => {
api.getBeefProduction(production.id, (error, data, response) => {
if (error) {
console.error(error);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useState } from "react"
import { Button, ButtonGroup, Typography, Stepper, Step, StepLabel, StepContent } from "@mui/material"
import { DatePickerElement, FormContainer, SliderElement, TextFieldElement } from 'react-hook-form-mui'

import { AuthenticatedApiBuilder } from '../../../api/AuthenticatedApiBuilder'
import { ApiBuilder } from '../../../api/ApiBuilder.ts'
import { useKeycloak } from '@react-keycloak/web'

import { LocalizationProvider } from "@mui/x-date-pickers"
Expand All @@ -22,7 +22,7 @@ export default function BeefProductionForm({ callback }) {
const { keycloak, initialized } = useKeycloak()
const [ activeStep, setActiveStep ] = useState(SET_PRODUCTION_PROPERTIES_STEP)
const [ beefProduction, setBeefProduction] = useState(new BeefProduction())
const authenticatedApiBuilder = new AuthenticatedApiBuilder()
const apiBuilder = new ApiBuilder()

return <>
<Typography variant="h6">Nouvel abattage bovin</Typography>
Expand Down Expand Up @@ -93,8 +93,8 @@ export default function BeefProductionForm({ callback }) {
}

function validate() {
authenticatedApiBuilder.getAuthenticatedApi(keycloak).then(api => {
authenticatedApiBuilder.invokeAuthenticatedApi(() => {
apiBuilder.getAuthenticatedApi(keycloak).then(api => {
apiBuilder.invokeAuthenticatedApi(() => {
api.createBeefProduction(beefProduction, (error, data, response) => {
if (error) {
console.error(error)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react'
import { useEffect, useState } from "react"
import { useKeycloak } from '@react-keycloak/web'
import { AuthenticatedApiBuilder } from '../../../api/AuthenticatedApiBuilder'
import { ApiBuilder } from '../../../api/ApiBuilder.ts'
import PackageLot from "viandeendirect_eu/dist/model/PackageLot"
import PackageLotsConfigurator from "../components/PackageLotConfigurator"

Expand All @@ -10,11 +10,11 @@ export default function PackageLotsCreator() {

const { keycloak, initialized } = useKeycloak()
const [packageLots, setPackageLots] = useState([])
const authenticatedApiBuilder = new AuthenticatedApiBuilder()
const apiBuilder = new ApiBuilder()

useEffect(() => {
authenticatedApiBuilder.getAuthenticatedApi(keycloak).then(api => {
authenticatedApiBuilder.invokeAuthenticatedApi(() => {
apiBuilder.getAuthenticatedApi(keycloak).then(api => {
apiBuilder.invokeAuthenticatedApi(() => {
api.getPackageTemplates((error, data, response) => {
if (error) {
console.error(error);
Expand Down
8 changes: 4 additions & 4 deletions frontend/app/src/domains/production/views/ProductionsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react'
import { useEffect, useState } from 'react'

import { useKeycloak } from '@react-keycloak/web'
import { AuthenticatedApiBuilder } from '../../../api/AuthenticatedApiBuilder'
import { ApiBuilder } from '../../../api/ApiBuilder.ts'

import { Button, Typography } from "@mui/material"

Expand All @@ -12,15 +12,15 @@ export default function ProductionsList({createBeefProductionCallback: createBee

const [productions, setProductions] = useState([])
const { keycloak, initialized } = useKeycloak()
const authenticatedApiBuilder = new AuthenticatedApiBuilder()
const apiBuilder = new ApiBuilder()

useEffect(() => {
loadProductions()
}, [keycloak])

function loadProductions() {
authenticatedApiBuilder.getAuthenticatedApi(keycloak).then(api => {
authenticatedApiBuilder.invokeAuthenticatedApi(() => {
apiBuilder.getAuthenticatedApi(keycloak).then(api => {
apiBuilder.invokeAuthenticatedApi(() => {
api.getProductions({}, (error, data, response) => {
if (error) {
console.error(error)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import { useEffect, useState } from 'react';
import { useKeycloak } from '@react-keycloak/web'
import { Typography } from "@mui/material"
import { AuthenticatedApiBuilder } from '../../../api/AuthenticatedApiBuilder.js'
import { ApiBuilder } from '../../../api/ApiBuilder.ts'
import { AnimalTypeUtils } from '../../../enum/AnimalType.ts';
import styles from './SaleCard.css'

export default function SaleCardBeefProduction({production: production}) {

const [productionPercentageSold, setProductionPercentageSold] = useState([])
const { keycloak, initialized } = useKeycloak()
const authenticatedApiBuilder = new AuthenticatedApiBuilder()
const apiBuilder = new ApiBuilder()

useEffect(() => {
loadProductionPercentageSold()
}, [keycloak])


function loadProductionPercentageSold() {
authenticatedApiBuilder.getAuthenticatedApi(keycloak).then(api => {
authenticatedApiBuilder.invokeAuthenticatedApi(() => {
apiBuilder.getAuthenticatedApi(keycloak).then(api => {
apiBuilder.invokeAuthenticatedApi(() => {
api.getProductionPercentageSold(production.id, (error, data, response) => {
if (error) {
console.error(error)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import { useState, useEffect } from 'react'
import { useKeycloak } from '@react-keycloak/web'
import { AuthenticatedApiBuilder } from '../../../api/AuthenticatedApiBuilder'
import { ApiBuilder } from '../../../api/ApiBuilder.ts'
import ProductionCard from '../../production/components/ProductionCard.tsx'

export default function SaleProductionSelector({selectProduction: selectProduction}) {

const { keycloak, initialized } = useKeycloak()
const [productionsForSale, setProductionsForSale] = useState([])
const authenticatedApiBuilder = new AuthenticatedApiBuilder()
const apiBuilder = new ApiBuilder()

useEffect(() => {
loadProductionsForSale()
}, [keycloak])

function loadProductionsForSale() {
authenticatedApiBuilder.getAuthenticatedApi(keycloak).then(api => {
authenticatedApiBuilder.invokeAuthenticatedApi(() => {
apiBuilder.getAuthenticatedApi(keycloak).then(api => {
apiBuilder.invokeAuthenticatedApi(() => {
api.getProductions({ 'forSale': true }, (error, data, response) => {
if (error) {
console.error(error)
Expand Down
20 changes: 10 additions & 10 deletions frontend/app/src/domains/sale/views/OrderForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Button, Stepper, Step, StepLabel, StepContent, Typography } from "@mui/
import dayjs from 'dayjs'

import { useKeycloak } from '@react-keycloak/web'
import { AuthenticatedApiBuilder } from '../../../api/AuthenticatedApiBuilder.js'
import { ApiBuilder } from '../../../api/ApiBuilder.ts'

import Customer from "viandeendirect_eu/dist/model/Customer"
import OrderItem from "viandeendirect_eu/dist/model/OrderItem"
Expand All @@ -25,7 +25,7 @@ export default function OrderForm({ sale: sale, returnCallback: returnCallback }
const CONFIRMATION_STEP = 3

const { keycloak, initialized } = useKeycloak()
const authenticatedApiBuilder = new AuthenticatedApiBuilder()
const apiBuilder = new ApiBuilder()

const [productions, setProductions] = useState<Array<Production>>([])
const [customers, setCustomers] = useState<Array<Customer>>([])
Expand All @@ -39,8 +39,8 @@ export default function OrderForm({ sale: sale, returnCallback: returnCallback }
}, [keycloak])

function loadProductions() {
authenticatedApiBuilder.getAuthenticatedApi(keycloak).then(api => {
authenticatedApiBuilder.invokeAuthenticatedApi(() => {
apiBuilder.getAuthenticatedApi(keycloak).then(api => {
apiBuilder.invokeAuthenticatedApi(() => {
api.getSaleProductions(sale.id, (error, data, response) => {
if (error) {
console.error(error)
Expand All @@ -54,8 +54,8 @@ export default function OrderForm({ sale: sale, returnCallback: returnCallback }
}

function loadCustomers() {
authenticatedApiBuilder.getAuthenticatedApi(keycloak).then(api => {
authenticatedApiBuilder.invokeAuthenticatedApi(() => {
apiBuilder.getAuthenticatedApi(keycloak).then(api => {
apiBuilder.invokeAuthenticatedApi(() => {
api.getCustomers((error, data, response) => {
if (error) {
console.error(error)
Expand Down Expand Up @@ -141,8 +141,8 @@ export default function OrderForm({ sale: sale, returnCallback: returnCallback }
}

function createCustomer(customer: Customer){
authenticatedApiBuilder.getAuthenticatedApi(keycloak).then(api => {
authenticatedApiBuilder.invokeAuthenticatedApi(() => {
apiBuilder.getAuthenticatedApi(keycloak).then(api => {
apiBuilder.invokeAuthenticatedApi(() => {
api.createCustomer(customer, (error, data, response) => {
if (error) {
console.error(error)
Expand All @@ -156,8 +156,8 @@ export default function OrderForm({ sale: sale, returnCallback: returnCallback }
}

function createOrder(order: Order) {
authenticatedApiBuilder.getAuthenticatedApi(keycloak).then(api => {
authenticatedApiBuilder.invokeAuthenticatedApi(() => {
apiBuilder.getAuthenticatedApi(keycloak).then(api => {
apiBuilder.invokeAuthenticatedApi(() => {
api.createOrder(order, (error, data, response) => {
if (error) {
console.error(error)
Expand Down
8 changes: 4 additions & 4 deletions frontend/app/src/domains/sale/views/OrderView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import { useEffect, useState } from 'react'
import { Button, Typography } from '@mui/material'

import { useKeycloak } from '@react-keycloak/web'
import { AuthenticatedApiBuilder } from '../../../api/AuthenticatedApiBuilder.js'
import { ApiBuilder } from '../../../api/ApiBuilder.ts'

import OrderSummary from '../components/OrderSummary.tsx'

export default function OrderView({order: rawOrder, sale: sale, returnCallback: returnCallback}) {

const { keycloak, initialized } = useKeycloak()
const authenticatedApiBuilder = new AuthenticatedApiBuilder()
const apiBuilder = new ApiBuilder()

const [order, setOrder] = useState([])

Expand All @@ -20,8 +20,8 @@ export default function OrderView({order: rawOrder, sale: sale, returnCallback:
}, [keycloak])

function loadOrder() {
authenticatedApiBuilder.getAuthenticatedApi(keycloak).then(api => {
authenticatedApiBuilder.invokeAuthenticatedApi(() => {
apiBuilder.getAuthenticatedApi(keycloak).then(api => {
apiBuilder.invokeAuthenticatedApi(() => {
api.getOrder(rawOrder.id, (error, data, response) => {
if (error) {
console.error(error)
Expand Down
8 changes: 4 additions & 4 deletions frontend/app/src/domains/sale/views/OrdersList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { DataGrid, GridRowsProp, GridColDef, GridToolbar } from '@mui/x-data-gri
import dayjs from 'dayjs'

import { useKeycloak } from '@react-keycloak/web'
import { AuthenticatedApiBuilder } from '../../../api/AuthenticatedApiBuilder.js'
import { ApiBuilder } from '../../../api/ApiBuilder.ts'

import Order from "viandeendirect_eu/dist/model/Order"

Expand All @@ -17,7 +17,7 @@ export default function OrdersList({
createOrderCallback: createOrderCallback}) {

const { keycloak, initialized } = useKeycloak()
const authenticatedApiBuilder = new AuthenticatedApiBuilder()
const apiBuilder = new ApiBuilder()

const [orders, setOrders] = useState([])

Expand All @@ -26,8 +26,8 @@ export default function OrdersList({
}, [keycloak])

function loadOrders() {
authenticatedApiBuilder.getAuthenticatedApi(keycloak).then(api => {
authenticatedApiBuilder.invokeAuthenticatedApi(() => {
apiBuilder.getAuthenticatedApi(keycloak).then(api => {
apiBuilder.invokeAuthenticatedApi(() => {
api.getSaleOrders(sale.id, (error, data, response) => {
if (error) {
console.error(error)
Expand Down
Loading

0 comments on commit 167e894

Please sign in to comment.