-
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
ed97dd7
commit 75ef6e6
Showing
18 changed files
with
268 additions
and
118 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,24 @@ | ||
import Customer from "viandeendirect_eu/dist/model/Customer" | ||
import Producer from "viandeendirect_eu/dist/model/Producer" | ||
import ProducerStatus from "viandeendirect_eu/dist/model/ProducerStatus" | ||
import Sale from "viandeendirect_eu/dist/model/Sale" | ||
|
||
export class MockApiProducers { | ||
|
||
getProducer(): Producer { | ||
return { | ||
id: 1, | ||
user: undefined, | ||
user: { | ||
id: 1, | ||
firstName: "Bob", | ||
lastName: "MARCEL", | ||
email: "[email protected]" | ||
}, | ||
status: 'ACTIVE', | ||
salesCredits: undefined, | ||
sales: undefined, | ||
productions: undefined | ||
productions: undefined, | ||
stripeAccount: undefined | ||
} | ||
} | ||
|
||
|
41 changes: 41 additions & 0 deletions
41
frontend/app/src/domains/commons/service/ProducerService.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,41 @@ | ||
import Keycloak from "keycloak-js" | ||
import Producer from "viandeendirect_eu/dist/model/Producer.js"; | ||
import { ApiInvoker } from "../../../api/ApiInvoker.ts"; | ||
import { AuthenticationService } from "../../../authentication/service/AuthenticationService.ts"; | ||
|
||
export class ProducerService { | ||
keycloak: Keycloak | ||
static producer: Producer | ||
static unauthorized: boolean | ||
|
||
constructor(keycloak: Keycloak) { | ||
this.keycloak = keycloak | ||
} | ||
|
||
loadProducer(setProducer, setUnauthorized = unauthorized => {}) { | ||
if(!ProducerService.producer) { | ||
const apiInvoker = new ApiInvoker() | ||
const authenticationService = new AuthenticationService(this.keycloak) | ||
apiInvoker.callApiAuthenticatedly( | ||
this.keycloak, | ||
api => api.getProducer, | ||
{'email': authenticationService.getCurrentUserEmail()}, | ||
producer => { | ||
ProducerService.producer = producer | ||
ProducerService.unauthorized = false | ||
setProducer(ProducerService.producer) | ||
setUnauthorized(ProducerService.unauthorized) | ||
}, | ||
error => { | ||
console.error(error) | ||
ProducerService.unauthorized = true | ||
setProducer(ProducerService.producer) | ||
setUnauthorized(ProducerService.unauthorized) | ||
} | ||
) | ||
} else { | ||
setProducer(ProducerService.producer) | ||
setUnauthorized(ProducerService.unauthorized) | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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,32 @@ | ||
import { useEffect, useState } from 'react' | ||
import CustomersList from './views/CustomersList.tsx' | ||
import React from 'react' | ||
import { useKeycloak } from '@react-keycloak/web' | ||
import { ProducerService } from '../commons/service/ProducerService.ts' | ||
import Producer from 'viandeendirect_eu/dist/model/Producer.js' | ||
import AuthenticatedLayout from '../../layouts/producer/AuthenticatedLayout.tsx' | ||
|
||
export default function CustomerController() { | ||
|
||
const { keycloak } = useKeycloak() | ||
const producerService = new ProducerService(keycloak) | ||
const [producer, setProducer] = useState<Producer>() | ||
|
||
const NONE = 'NONE' | ||
|
||
const [currentAction, setCurrentAction] = useState(NONE) | ||
|
||
useEffect(() => { | ||
producerService.loadProducer(setProducer) | ||
}) | ||
|
||
return <AuthenticatedLayout>{getContent()}</AuthenticatedLayout> | ||
|
||
function getContent() { | ||
if(producer) { | ||
switch (currentAction) { | ||
case 'NONE': return <CustomersList producer={producer}/> | ||
} | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
27 changes: 27 additions & 0 deletions
27
frontend/app/src/domains/dashboard/components/DashboardAccount.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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import React, { useEffect, useState } from 'react' | ||
import { Button, Typography } from "@mui/material" | ||
import Producer from 'viandeendirect_eu/dist/model/Producer.js' | ||
import { ApiInvoker } from '../../../api/ApiInvoker.ts' | ||
import { useKeycloak } from '@react-keycloak/web' | ||
import { AuthenticationService } from '../../../authentication/service/AuthenticationService.ts' | ||
import { ProducerService } from '../../commons/service/ProducerService.ts' | ||
|
||
|
||
function DashboardAccount() { | ||
|
||
const { keycloak } = useKeycloak() | ||
const producerService = new ProducerService(keycloak) | ||
const [producer, setProducer] = useState<Producer>() | ||
|
||
useEffect(() => { | ||
producerService.loadProducer(setProducer) | ||
}, [keycloak]) | ||
|
||
|
||
return <> | ||
<div>Bienvenue {producer?.user.firstName}</div> | ||
<Button onClick={() => window.open('./account', '_self')}>Gérer mon compte</Button> | ||
</> | ||
} | ||
|
||
export default DashboardAccount |
16 changes: 16 additions & 0 deletions
16
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import React, { useEffect, useState } from 'react' | ||
import { Button, Typography } from "@mui/material" | ||
import Producer from 'viandeendirect_eu/dist/model/Producer.js' | ||
import { ApiInvoker } from '../../../api/ApiInvoker.ts' | ||
import { useKeycloak } from '@react-keycloak/web' | ||
import { AuthenticationService } from '../../../authentication/service/AuthenticationService.ts' | ||
|
||
|
||
function DashboardProductions() { | ||
|
||
return <><div>Mes prochaines productions</div> | ||
<Button onClick={() => window.open('./productions', '_self')}>Gérer mes productions</Button> | ||
</> | ||
} | ||
|
||
export default DashboardProductions |
16 changes: 16 additions & 0 deletions
16
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import React, { useEffect, useState } from 'react' | ||
import { Button, Typography } from "@mui/material" | ||
import Producer from 'viandeendirect_eu/dist/model/Producer.js' | ||
import { ApiInvoker } from '../../../api/ApiInvoker.ts' | ||
import { useKeycloak } from '@react-keycloak/web' | ||
import { AuthenticationService } from '../../../authentication/service/AuthenticationService.ts' | ||
|
||
|
||
function DashboardSales() { | ||
|
||
return <><div>Mes prochaines ventes</div> | ||
<Button onClick={() => window.open('./sales', '_self')}>Gérer mes ventes</Button> | ||
</> | ||
} | ||
|
||
export default DashboardSales |
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,9 @@ | ||
.dashboard-container { | ||
display: flex; | ||
flex-wrap: wrap; | ||
} | ||
|
||
.dashboard-item { | ||
min-width: 20rem; | ||
flex: 1 1 50%; | ||
} |
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,21 @@ | ||
import React from 'react' | ||
import { Typography } from "@mui/material" | ||
import './Dashboard.css' | ||
import DashboardAccount from '../components/DashboardAccount.tsx' | ||
import AuthenticatedLayout from '../../../layouts/producer/AuthenticatedLayout.tsx' | ||
import DashboardProductions from '../components/DashboardProductions.tsx' | ||
import DashboardSales from '../components/DashboardSales.tsx' | ||
|
||
function Dashboard() { | ||
return <AuthenticatedLayout> | ||
<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 |
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
Oops, something went wrong.