Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2897 navigate to returns #6752

Open
wants to merge 4 commits into
base: v2.6.0-RC
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export type UpdateSupplierReturnLinesMutationVariables = Types.Exact<{
}>;


export type UpdateSupplierReturnLinesMutation = { __typename: 'Mutations', updateSupplierReturnLines: { __typename: 'InvoiceNode', id: string } };
export type UpdateSupplierReturnLinesMutation = { __typename: 'Mutations', updateSupplierReturnLines: { __typename: 'InvoiceNode', id: string, invoiceNumber: number } };

export type InsertCustomerReturnMutationVariables = Types.Exact<{
storeId: Types.Scalars['String']['input'];
Expand Down Expand Up @@ -129,7 +129,7 @@ export type UpdateCustomerReturnLinesMutationVariables = Types.Exact<{
}>;


export type UpdateCustomerReturnLinesMutation = { __typename: 'Mutations', updateCustomerReturnLines: { __typename: 'InvoiceNode', id: string } };
export type UpdateCustomerReturnLinesMutation = { __typename: 'Mutations', updateCustomerReturnLines: { __typename: 'InvoiceNode', id: string, invoiceNumber: number } };

export type DeleteCustomerReturnMutationVariables = Types.Exact<{
storeId: Types.Scalars['String']['input'];
Expand Down Expand Up @@ -495,6 +495,7 @@ export const UpdateSupplierReturnLinesDocument = gql`
... on InvoiceNode {
__typename
id
invoiceNumber
}
}
}
Expand Down Expand Up @@ -543,6 +544,7 @@ export const UpdateCustomerReturnLinesDocument = gql`
... on InvoiceNode {
__typename
id
invoiceNumber
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needed to update api to find invoice number when updating lines

}
}
}
Expand Down
2 changes: 2 additions & 0 deletions client/packages/invoices/src/Returns/api/operations.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ mutation updateSupplierReturnLines(
... on InvoiceNode {
__typename
id
invoiceNumber
}
}
}
Expand Down Expand Up @@ -414,6 +415,7 @@ mutation updateCustomerReturnLines(
... on InvoiceNode {
__typename
id
invoiceNumber
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ import {
ModalMode,
Box,
AlertColor,
useNavigate,
RouteBuilder,
} from '@openmsupply-client/common';
import { ItemSelector } from './ItemSelector';
import { ReturnSteps, Tabs } from './ReturnSteps';
import { useReturns } from '../../api';
import { useDraftCustomerReturnLines } from './useDraftCustomerReturnLines';
import { AppRoute } from 'packages/config/src';

interface CustomerReturnEditModalProps {
isOpen: boolean;
Expand Down Expand Up @@ -52,6 +55,7 @@ export const CustomerReturnEditModal = ({
);

const alertRef = useRef<HTMLDivElement>(null);
const navigate = useNavigate();

const [zeroQuantityAlert, setZeroQuantityAlert] = useState<
AlertColor | undefined
Expand All @@ -78,7 +82,15 @@ export const CustomerReturnEditModal = ({

const onOk = async () => {
try {
!isDisabled && (await save());
if (isDisabled === false) {
const invoiceNumber = await save();
navigate(
RouteBuilder.create(AppRoute.Replenishment)
.addPart(AppRoute.SupplierReturn)
.addPart(invoiceNumber.toString())
.build()
)
};
onCreate?.();
onClose();
} catch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,19 +114,17 @@ export const useDraftCustomerReturnLines = ({

// TODO: error handling here
// also need to consider what we do if the error was on the first page of the wizard
if (!returnId) {
await insert({
id: FnUtils.generateUUID(),
customerId,
outboundShipmentId,
customerReturnLines,
});
} else {
await updateLines({
customerReturnId: returnId,
customerReturnLines,
});
}
const returnOp = returnId ? await updateLines({
customerReturnId: returnId,
customerReturnLines,
}) : await insert({
id: FnUtils.generateUUID(),
customerId,
outboundShipmentId,
customerReturnLines,
});
return typeof returnOp === "number" ? returnOp : returnOp.invoiceNumber;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awaiting update / insert and then converting to always return a number to be consumer focussed.


};

return { lines: draftLines, update, save, addDraftLine };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ import {
Box,
ModalMode,
AlertColor,
useNavigate,
RouteBuilder,
} from '@openmsupply-client/common';
import { ItemSelector } from './ItemSelector';
import { ReturnSteps, Tabs } from './ReturnSteps';
import { useReturns } from '../../api';
import { useDraftSupplierReturnLines } from './useDraftSupplierReturnLines';
import { AppRoute } from 'packages/config/src';

interface SupplierReturnEditModalProps {
isOpen: boolean;
Expand Down Expand Up @@ -50,6 +53,7 @@ export const SupplierReturnEditModal = ({
initialItemId ?? undefined
);
const alertRef = useRef<HTMLDivElement>(null);
const navigate = useNavigate();

const [zeroQuantityAlert, setZeroQuantityAlert] = useState<
AlertColor | undefined
Expand All @@ -76,7 +80,15 @@ export const SupplierReturnEditModal = ({

const onOk = async () => {
try {
!isDisabled && (await save());
if (isDisabled === false) {
const invoiceNumber = await save();
navigate(
RouteBuilder.create(AppRoute.Replenishment)
.addPart(AppRoute.SupplierReturn)
.addPart(invoiceNumber.toString())
.build()
)
};
onCreate?.();
onClose();
} catch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,17 @@ export const useDraftSupplierReturnLines = ({
}
);

if (!returnId) {
await insert({
id: FnUtils.generateUUID(),
supplierId,
inboundShipmentId,
supplierReturnLines,
});
} else {
await updateLines({
supplierReturnId: returnId,
supplierReturnLines,
});
}
const returnOp = returnId ? await updateLines({
supplierReturnId: returnId,
supplierReturnLines,
}) : await insert({
id: FnUtils.generateUUID(),
supplierId,
inboundShipmentId,
supplierReturnLines,
});

return typeof returnOp === "number" ? returnOp : returnOp.invoiceNumber;
// TODO: error handling here
// also need to consider what we do if the error was on the first page of the wizard
};
Expand Down