-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2751ad0
commit a31d597
Showing
6 changed files
with
124 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 42 additions & 4 deletions
46
frontend/app/src/domains/dashboard/components/DashboardProductions.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 39 additions & 4 deletions
43
frontend/app/src/domains/dashboard/components/DashboardSales.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,45 @@ | ||
import React, { useEffect, useState } from 'react' | ||
import { Button, Typography } from "@mui/material" | ||
import { useKeycloak } from '@react-keycloak/web' | ||
import { Button } from "@mui/material" | ||
import { Producer, Sale } from '@viandeendirect/api/dist/models' | ||
import SaleCard from '../../sale/components/SaleCard.tsx' | ||
import { ApiBuilder } from '../../../api/ApiBuilder.ts' | ||
import { ProducerService } from '../../commons/service/ProducerService.ts' | ||
import { useNavigate } from 'react-router-dom' | ||
|
||
|
||
export default function DashboardSales() { | ||
|
||
return <><div>Mes prochaines ventes</div> | ||
<Button onClick={() => window.open('./sales', '_self')}>Gérer mes ventes</Button> | ||
</> | ||
const {keycloak} = useKeycloak() | ||
const [nextSale, setNextSale] = useState<Sale | undefined>(undefined) | ||
const apiBuilder = new ApiBuilder() | ||
const navigate = useNavigate() | ||
|
||
useEffect(() => { | ||
const loadNextSale = async () => { | ||
const producerService = new ProducerService(keycloak) | ||
const producer: Producer = await producerService.loadProducer() | ||
const api = await apiBuilder.getAuthenticatedApi(keycloak) | ||
const producerSales = await api.getProducerSales({producerId: +producer.id}) | ||
const nextSale = producerSales | ||
.filter(sale => sale.deliveryStart && sale.deliveryStart > new Date()) | ||
.sort((sale1, sale2) => (sale1.deliveryStart > sale2.deliveryStart) ? 1 : -1)[0] | ||
setNextSale(nextSale) | ||
} | ||
loadNextSale() | ||
}, [keycloak]) | ||
|
||
function displayNextSaleCard(): React.ReactNode { | ||
if (nextSale) { | ||
return <SaleCard sale={nextSale}/> | ||
} | ||
return <div>Aucune vente programmée pour le moment.</div> | ||
} | ||
|
||
return <><div>Ma prochaine vente</div> | ||
<div className='card-list'> | ||
{displayNextSaleCard()} | ||
</div> | ||
<Button onClick={() => navigate('/sales')}>Gérer mes ventes</Button> | ||
</> | ||
} |
27 changes: 27 additions & 0 deletions
27
frontend/app/src/domains/production/service/ProductionService.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import Keycloak from "keycloak-js" | ||
import { Production } from "@viandeendirect/api/dist/models"; | ||
import { ApiBuilder } from "../../../api/ApiBuilder.ts"; | ||
|
||
export class ProductionService { | ||
keycloak: Keycloak | ||
apiBuilder: ApiBuilder | ||
|
||
constructor(keycloak: Keycloak) { | ||
this.keycloak = keycloak | ||
this.apiBuilder = new ApiBuilder(); | ||
} | ||
|
||
|
||
async getProductionEnd(production: Production): Promise<Date | undefined> { | ||
const api = await this.apiBuilder.getAuthenticatedApi(this.keycloak) | ||
switch (production.productionType) { | ||
case 'BeefProduction': | ||
const beefProduction = await api.getBeefProduction({beefProductionId: +production.id}) | ||
return beefProduction.cuttingDate | ||
case 'HonneyProduction': | ||
return undefined | ||
default: | ||
return undefined | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters