Skip to content

Commit

Permalink
feat: implemented delivery information in the frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
ReneSchroederLJ authored May 13, 2024
1 parent d33e1df commit a81a368
Show file tree
Hide file tree
Showing 28 changed files with 998 additions and 147 deletions.
10 changes: 9 additions & 1 deletion charts/puris/templates/frontend-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,15 @@ spec:
- name: ENDPOINT_UPDATE_REPORTED_PRODUCT_STOCKS
value: "{{ .Values.frontend.puris.endpointUpdateReportedProductStocks }}"
- name: ENDPOINT_PARTNER_OWNSITES
value: "{{ .Values.frontend.puris.endpointPartnerOwnSites }}"
value: "{{ .Values.frontend.puris.endpointPartnerOwnSites }}"
- name: ENDPOINT_DEMAND
value: "{{ .Values.frontend.puris.endpointDemand }}"
- name: ENDPOINT_PRODUCTION
value: "{{ .Values.frontend.puris.endpointProduction }}"
- name: ENDPOINT_PRODUCTION_RANGE
value: "{{ .Values.frontend.puris.endpointProductionRange }}"
- name: ENDPOINT_DELIVERY
value: "{{ .Values.frontend.puris.endpointDelivery }}"
- name: BACKEND_API_KEY
value: "{{ .Values.backend.puris.api.key}}"
- name: IDP_DISABLE
Expand Down
8 changes: 8 additions & 0 deletions charts/puris/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,14 @@ frontend:
endpointUpdateReportedProductStocks: stockView/update-reported-product-stocks?ownMaterialNumber=
# -- The endpoint for the partners BPNS
endpointPartnerOwnSites: partners/ownSites
# -- The endpoint for the demand submodel
endpointDemand: demand
# -- The endpoint for the production submodel
endpointProduction: production
# -- The endpoint for the production range of the production submodel
endpointProductionRange: production/range
# -- The endpoint for the delivery submodel
endpointDelivery: delivery
keycloak:
# -- Disable the Keycloak integration.
disabled: true
Expand Down
1 change: 1 addition & 0 deletions frontend/.env
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ VITE_ENDPOINT_PARTNER_OWNSITES=partners/ownSites
VITE_ENDPOINT_DEMAND=demand
VITE_ENDPOINT_PRODUCTION=production
VITE_ENDPOINT_PRODUCTION_RANGE=production/range
VITE_ENDPOINT_DELIVERY=delivery

VITE_IDP_DISABLE=true
VITE_IDP_URL=http://localhost:10081/
Expand Down
1 change: 1 addition & 0 deletions frontend/.env.dockerbuild
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ VITE_ENDPOINT_PARTNER_OWNSITES=\$ENDPOINT_PARTNER_OWNSITES
VITE_ENDPOINT_DEMAND=\$ENDPOINT_DEMAND
VITE_ENDPOINT_PRODUCTION=\$ENDPOINT_PRODUCTION
VITE_ENDPOINT_PRODUCTION_RANGE=\$ENDPOINT_PRODUCTION_RANGE
VITE_ENDPOINT_DELIVERY=\$ENDPOINT_DELIVERY

VITE_IDP_DISABLE=\$IDP_DISABLE
VITE_IDP_URL=\$IDP_URL
Expand Down
82 changes: 53 additions & 29 deletions frontend/src/features/dashboard/components/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,23 @@ import { PlannedProductionModal } from './PlannedProductionModal';
import { useProduction } from '../hooks/useProduction';
import { useReportedProduction } from '../hooks/useReportedProduction';

import { refreshPartnerStocks } from '@services/stocks-service';
import { requestReportedStocks } from '@services/stocks-service';
import { useReportedDelivery } from '../hooks/useReportedDelivery';
import { useDelivery } from '../hooks/useDelivery';
import { requestReportedDeliveries } from '@services/delivery-service';
import { requestReportedProductions } from '@services/productions-service';
import { requestReportedDemands } from '@services/demands-service';
import { ModalMode } from '@models/types/data/modal-mode';

const NUMBER_OF_DAYS = 28;

type DashboardState = {
selectedMaterial: MaterialDescriptor | null;
selectedSite: Site | null;
selectedPartnerSites: Site[] | null;
deliveryDialogOptions: { open: boolean; mode: 'create' | 'edit' };
demandDialogOptions: { open: boolean; mode: 'create' | 'edit' };
productionDialogOptions: { open: boolean; mode: 'create' | 'edit' };
deliveryDialogOptions: { open: boolean; mode: ModalMode, direction: 'incoming' | 'outgoing', site: Site | null };
demandDialogOptions: { open: boolean; mode: ModalMode };
productionDialogOptions: { open: boolean; mode: ModalMode };
delivery: Delivery | null;
demand: Partial<Demand> | null;
production: Partial<Production> | null;
Expand All @@ -71,7 +77,7 @@ const initialState: DashboardState = {
selectedMaterial: null,
selectedSite: null,
selectedPartnerSites: null,
deliveryDialogOptions: { open: false, mode: 'create' },
deliveryDialogOptions: { open: false, mode: 'edit', direction: 'incoming', site: null },
demandDialogOptions: { open: false, mode: 'edit' },
productionDialogOptions: { open: false, mode: 'edit' },
delivery: null,
Expand All @@ -83,7 +89,7 @@ const initialState: DashboardState = {
export const Dashboard = ({ type }: { type: 'customer' | 'supplier' }) => {
const [state, dispatch] = useReducer(reducer, initialState);
const { stocks } = useStocks(type === 'customer' ? 'material' : 'product');
const { partnerStocks, refreshPartnerStocks: refresh } = usePartnerStocks(
const { partnerStocks } = usePartnerStocks(
type === 'customer' ? 'material' : 'product',
state.selectedMaterial?.ownMaterialNumber ?? null
);
Expand All @@ -94,25 +100,38 @@ export const Dashboard = ({ type }: { type: 'customer' | 'supplier' }) => {
state.selectedSite?.bpns ?? null
);
const { reportedProductions } = useReportedProduction(state.selectedMaterial?.ownMaterialNumber ?? null);
const { deliveries, refreshDelivery } = useDelivery(
state.selectedMaterial?.ownMaterialNumber ?? null,
state.selectedSite?.bpns ?? null
);
const { reportedDeliveries } = useReportedDelivery(state.selectedMaterial?.ownMaterialNumber ?? null);

const handleRefresh = () => {
dispatch({ type: 'isRefreshing', payload: true });
refreshPartnerStocks( type === 'customer' ? 'material' : 'product', state.selectedMaterial?.ownMaterialNumber ?? null )
.then(refresh)
.finally(() => dispatch({ type: 'isRefreshing', payload: false }));
Promise.all([
requestReportedStocks(type === 'customer' ? 'material' : 'product', state.selectedMaterial?.ownMaterialNumber ?? null),
requestReportedDeliveries(state.selectedMaterial?.ownMaterialNumber ?? null),
type === 'customer'
? requestReportedProductions(state.selectedMaterial?.ownMaterialNumber ?? null)
: requestReportedDemands(state.selectedMaterial?.ownMaterialNumber ?? null)
]).finally(() => dispatch({ type: 'isRefreshing', payload: false }));
};
const openDeliveryDialog = (d: Partial<Delivery>) => {
const openDeliveryDialog = useCallback(
(d: Partial<Delivery>, mode: ModalMode, direction: 'incoming' | 'outgoing' = 'outgoing', site: Site | null) => {
d.ownMaterialNumber = state.selectedMaterial?.ownMaterialNumber ?? '';
dispatch({ type: 'delivery', payload: d });
dispatch({ type: 'deliveryDialogOptions', payload: { open: true, mode: 'edit' } });
};
const openDemandDialog = (d: Partial<Demand>, mode: 'create' | 'edit') => {
dispatch({ type: 'deliveryDialogOptions', payload: { open: true, mode, direction, site } });
},
[state.selectedMaterial?.ownMaterialNumber]
);
const openDemandDialog = (d: Partial<Demand>, mode: ModalMode) => {
d.measurementUnit ??= 'unit:piece';
d.demandCategoryCode ??= DEMAND_CATEGORY[0]?.key;
d.ownMaterialNumber = state.selectedMaterial?.ownMaterialNumber ?? '';
dispatch({ type: 'demand', payload: d });
dispatch({ type: 'demandDialogOptions', payload: { open: true, mode } });
};
const openProductionDialog = (p: Partial<Production>, mode: 'create' | 'edit') => {
const openProductionDialog = (p: Partial<Production>, mode: ModalMode) => {
p.material ??= {
materialFlag: true,
productFlag: false,
Expand Down Expand Up @@ -154,18 +173,20 @@ export const Dashboard = ({ type }: { type: 'customer' | 'supplier' }) => {
numberOfDays={NUMBER_OF_DAYS}
stocks={stocks ?? []}
site={state.selectedSite}
onDeliveryClick={openDeliveryDialog}
onDeliveryClick={(delivery, mode) => openDeliveryDialog(delivery, mode, 'outgoing', state.selectedSite)}
onProductionClick={openProductionDialog}
productions={productions ?? []}
deliveries={deliveries ?? []}
/>
) : (
<DemandTable
numberOfDays={NUMBER_OF_DAYS}
stocks={stocks}
site={state.selectedSite}
onDeliveryClick={openDeliveryDialog}
onDeliveryClick={(delivery, mode) => openDeliveryDialog(delivery, mode, 'incoming', state.selectedSite)}
onDemandClick={openDemandDialog}
demands={demands}
deliveries={reportedDeliveries}
/>
)
) : (
Expand Down Expand Up @@ -209,9 +230,10 @@ export const Dashboard = ({ type }: { type: 'customer' | 'supplier' }) => {
numberOfDays={NUMBER_OF_DAYS}
stocks={partnerStocks}
site={ps}
onDeliveryClick={openDeliveryDialog}
onDeliveryClick={(delivery, mode) => openDeliveryDialog(delivery, mode, 'incoming', ps)}
onDemandClick={openDemandDialog}
demands={reportedDemands?.filter((d) => d.demandLocationBpns === ps.bpns) ?? []}
deliveries={deliveries ?? []}
readOnly
/>
) : (
Expand All @@ -220,9 +242,10 @@ export const Dashboard = ({ type }: { type: 'customer' | 'supplier' }) => {
numberOfDays={NUMBER_OF_DAYS}
stocks={partnerStocks ?? []}
site={ps}
onDeliveryClick={openDeliveryDialog}
onDeliveryClick={(delivery, mode) => openDeliveryDialog(delivery, mode, 'outgoing', ps)}
onProductionClick={openProductionDialog}
productions={reportedProductions?.filter((p) => p.productionSiteBpns === ps.bpns) ?? []}
deliveries={reportedDeliveries ?? []}
readOnly
/>
)
Expand All @@ -236,27 +259,28 @@ export const Dashboard = ({ type }: { type: 'customer' | 'supplier' }) => {
</Stack>
)}
</Stack>
<DeliveryInformationModal
open={state.deliveryDialogOptions.open}
onClose={() =>
dispatch({ type: 'deliveryDialogOptions', payload: { open: false, mode: state.deliveryDialogOptions.mode } })
}
delivery={state.delivery}
/>
<DemandCategoryModal
open={state.demandDialogOptions.open}
mode={state.demandDialogOptions.mode}
{...state.demandDialogOptions}
onClose={() => dispatch({ type: 'demandDialogOptions', payload: { open: false, mode: state.demandDialogOptions.mode } })}
onSave={refreshDemand}
demand={state.demand}
demands={demands ?? []}
demands={(state.demandDialogOptions.mode === 'view' ? reportedDemands : demands) ?? []}
/>
<PlannedProductionModal
{...state.productionDialogOptions}
onClose={() => dispatch({ type: 'productionDialogOptions', payload: { open: false, mode: state.productionDialogOptions.mode } })}
onSave={refreshProduction}
production={state.production}
productions={state.productionDialogOptions.mode === 'edit' ? productions ?? [] : []}
productions={(state.productionDialogOptions.mode === 'view' ? reportedProductions : productions) ?? []}
/>
<DeliveryInformationModal
{...state.deliveryDialogOptions}
onClose={() =>
dispatch({ type: 'deliveryDialogOptions', payload: { ...state.deliveryDialogOptions, open: false, } })
}
onSave={refreshDelivery}
delivery={state.delivery}
deliveries={(type === 'customer' ? reportedDeliveries : deliveries) ?? []}
/>
</>
);
Expand Down
Loading

0 comments on commit a81a368

Please sign in to comment.