-
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.
convert loading with callbacks to react-router-loaders (...suite, pro…
…ducer area finished, customer area begin...)
- Loading branch information
1 parent
03c43f2
commit b878d48
Showing
20 changed files
with
248 additions
and
442 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
Faire fonctionner le la modification d'un abattage bovin | ||
Revoir le fonctionnement du contrôle producteur / client | ||
Finir la migration avec react-router pour l'espace client |
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
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
171 changes: 0 additions & 171 deletions
171
frontend/app/src/domains/producer/ProducerController.tsx
This file was deleted.
Oops, something went wrong.
79 changes: 79 additions & 0 deletions
79
frontend/app/src/domains/producer/views/ProducerAccountView.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,79 @@ | ||
import React from 'react' | ||
import { useState } from 'react' | ||
|
||
import { Button, Typography, CircularProgress } from "@mui/material" | ||
|
||
import { useKeycloak } from '@react-keycloak/web'; | ||
import { Producer } from '@viandeendirect/api/dist/models/Producer.js'; | ||
import { ProducerService } from '../../commons/service/ProducerService.ts'; | ||
import { ApiBuilder } from '../../../api/ApiBuilder.ts'; | ||
import { StripeAccount } from '@viandeendirect/api/dist/models/StripeAccount'; | ||
import { useLoaderData } from 'react-router-dom'; | ||
|
||
|
||
export default function ProducerAccountView() { | ||
|
||
const {keycloak} = useKeycloak() | ||
const apiBuilder = new ApiBuilder() | ||
const loadedProducer: Producer = useLoaderData() | ||
const [producer, setProducer] = useState<Producer>(loadedProducer) | ||
const [stripeAccountCreationPending, setStripeAccountCreationPending] = useState<boolean>(false) | ||
|
||
return <> | ||
<Typography variant="h6">Gestion du compte</Typography> | ||
{displayStripeAccount()} | ||
</> | ||
|
||
function displayStripeAccount() { | ||
if (producer?.stripeAccount) { | ||
return <> | ||
<div>Votre numéro de compte Stripe est {producer.stripeAccount.stripeId}</div> | ||
{displayStripeAccountLink()} | ||
</> | ||
} else { | ||
return <Button disabled={stripeAccountCreationPending} onClick={createStripeAccount}> | ||
Créer un compte de paiement Stripe | ||
{displayStripeAccountCreationProgress()} | ||
</Button> | ||
} | ||
} | ||
|
||
function displayStripeAccountLink() { | ||
if(producer?.stripeAccount) { | ||
if (!producer.stripeAccount.detailsSubmitted) { | ||
return <Button onClick={() => window.location.href = producer.stripeAccount.accountLink}>Saisissez votre RIB et vos informations réglementaires sur Stripe</Button> | ||
} else { | ||
return <> | ||
<Button onClick={() => window.open('https://dashboard.stripe.com/', '_blank')}>Consultez vos encaissements sur Stripe</Button> | ||
<Button onClick={() => window.open(producer.stripeAccount.accountLink, '_self')}>Modifier votre RIB et vos informations réglementaires sur Stripe</Button> | ||
</> | ||
} | ||
} | ||
} | ||
|
||
function displayStripeAccountCreationProgress() { | ||
if (stripeAccountCreationPending) { | ||
return <CircularProgress/> | ||
} | ||
} | ||
|
||
async function createStripeAccount() { | ||
setStripeAccountCreationPending(true) | ||
const api = await apiBuilder.getAuthenticatedApi(keycloak) | ||
const stripeAccount = await api.createStripeAccount({producerId: +producer.id}) | ||
setProducer({...producer, stripeAccount: stripeAccount}) | ||
setStripeAccountCreationPending(false) | ||
} | ||
} | ||
|
||
export async function loadProducerAccountViewData(keycloak) { | ||
const producerService = new ProducerService(keycloak) | ||
const producer: Producer = await producerService.asyncLoadProducer() | ||
const apiBuilder = new ApiBuilder(); | ||
const api = await apiBuilder.getAuthenticatedApi(keycloak); | ||
if (producer.stripeAccount) { | ||
const stripeAccount: StripeAccount = await api.getStripeAccount({producerId: +producer.id}) | ||
return {...producer, stripeAccount: stripeAccount} | ||
} | ||
return producer | ||
} |
Oops, something went wrong.