-
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...)
- Loading branch information
1 parent
8ef10b1
commit c4c9245
Showing
10 changed files
with
159 additions
and
183 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
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 |
---|---|---|
|
@@ -12,7 +12,6 @@ export class MockApiCustomers { | |
email: '[email protected]' | ||
} | ||
} | ||
//return undefined | ||
} | ||
|
||
createCustomer(customer: Customer): Customer { | ||
|
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
29 changes: 2 additions & 27 deletions
29
frontend/app/src/domains/sale/components/SaleProductionSelector.js
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,42 +1,27 @@ | ||
import React from 'react' | ||
import { useEffect, useState } from 'react' | ||
import { useLoaderData, useNavigate } from 'react-router-dom' | ||
|
||
import { Button, Typography } from '@mui/material' | ||
|
||
import { useKeycloak } from '@react-keycloak/web' | ||
import { ApiBuilder } from '../../../api/ApiBuilder.ts' | ||
|
||
import OrderSummary from '../components/OrderSummary.tsx' | ||
import { Order } from '@viandeendirect/api/dist/models/Order' | ||
|
||
export default function OrderView({order: rawOrder, sale: sale, returnCallback: returnCallback}) { | ||
export default function OrderView() { | ||
|
||
const { keycloak, initialized } = useKeycloak() | ||
const apiBuilder = new ApiBuilder() | ||
|
||
const [order, setOrder] = useState([]) | ||
|
||
useEffect(() => { | ||
loadOrder() | ||
}, [keycloak]) | ||
|
||
function loadOrder() { | ||
apiBuilder.getAuthenticatedApi(keycloak).then(api => { | ||
apiBuilder.invokeAuthenticatedApi(() => { | ||
api.getOrder(rawOrder.id, (error, data, response) => { | ||
if (error) { | ||
console.error(error) | ||
} else { | ||
console.log('api.getOrder called successfully. Returned data: ' + data) | ||
setOrder(data) | ||
} | ||
}) | ||
}, keycloak) | ||
}) | ||
} | ||
const navigate = useNavigate() | ||
const order: Order = useLoaderData() | ||
|
||
return <> | ||
<Typography variant='h6'>Détails de la commande</Typography> | ||
<OrderSummary order={order}></OrderSummary> | ||
<Button onClick={() => returnCallback(sale)}>Retour aux commandes</Button> | ||
<Button onClick={() => navigate(-1)}>Retour aux commandes</Button> | ||
</> | ||
} | ||
|
||
export async function loadOrderViewData(orderId: number, keycloakClient): Promise<Order> { | ||
const apiBuilder = new ApiBuilder() | ||
const api = await apiBuilder.getAuthenticatedApi(keycloakClient) | ||
return await api.getOrder({orderId}) | ||
} |
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.