Skip to content

Commit

Permalink
refactor: clean up code
Browse files Browse the repository at this point in the history
  • Loading branch information
fhenrich33 committed Nov 9, 2024
1 parent f5ccd75 commit 9caa0e2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ function CreateShipmentView() {
// Handle Submission
const onSubmitCreateShipmentForm = useCallback(
(createShipmentFormData: ICreateShipmentFormData) => {
console.log(createShipmentFormData);
// Find the possible agreement Ids for the partner base
// Or ignore this and return an empty array if this is a intra-org shipment between bases of the same organization.
const agreementIds: Array<string> =
createShipmentFormData.shipmentTarget === "currentOrg"
? []
Expand All @@ -179,7 +179,6 @@ function CreateShipmentView() {
)
.map((org) => org.agreementId) || [];

// Valid to not have agreements for intra org shipments.
if (agreementIds.length === 0 && createShipmentFormData.shipmentTarget === "partners") {
triggerError({
message: "Error while trying to create a new shipment",
Expand Down Expand Up @@ -232,7 +231,6 @@ function CreateShipmentView() {
return <APILoadingIndicator />;
}

// Valid to not have agreements for intra org shipments.
const renderNoAcceptedAgreementsAlert = (
<Alert status="warning">
<AlertIcon />
Expand All @@ -250,17 +248,14 @@ function CreateShipmentView() {
</Alert>
);

// Valid to not have agreements for intra org shipments.
const noAcceptedAgreements = allAcceptedTransferAgreements.data?.transferAgreements.length === 0;
const noPartnerOrgBaseData =
!partnerOrganisationBaseData || partnerOrganisationBaseData.length === 0;

// Valid to not have agreements for intra org shipments.
if (noAcceptedAgreements) {
return renderNoAcceptedAgreementsAlert;
}

// Valid to not have agreements for intra org shipments.
if (noPartnerOrgBaseData || allAcceptedTransferAgreements.error) {
return renderErrorAlert;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ function CreateShipment({
});

setValueIntraOrg("receivingOrganisation", {
label: currentOrganisationLabel.split(" - ")[0],
label: currentOrganisationLabel,
value: currentOrganisationId,
});

Expand All @@ -117,6 +117,14 @@ function CreateShipment({
value: organisation.id,
}));

// Prepare options for the organisation field, but for intra-org shipments
const intraOrganisationOptions = currentOrganisationBases
.filter((base) => base.id !== baseId)
.map((base) => ({
value: base.id,
label: base.name,
}));

// selected Option for organisation field
const receivingOrganisation = watch("receivingOrganisation");

Expand Down Expand Up @@ -295,10 +303,7 @@ function CreateShipment({
placeholder="Please select a base"
errors={errorsIntraOrg}
control={controlIntraOrg}
options={currentOrganisationBases.map((base) => ({
value: base.id,
label: base.name,
}))}
options={intraOrganisationOptions}
/>
</ListItem>
</List>
Expand Down

0 comments on commit 9caa0e2

Please sign in to comment.