@@ -13,9 +13,9 @@ import { useState } from "react";
1313import { BsFillCheckCircleFill } from "react-icons/bs" ;
1414import { RiQuestionFill } from "react-icons/ri" ;
1515import { ILocationData , IProductWithSizeRangeData } from "./BoxReconciliationView" ;
16- import { IMatchProductsFormData , MatchProductsForm } from "./MatchProductsForm" ;
16+ import { MatchProductsFormData , MatchProductsForm } from "./MatchProductsForm" ;
1717import { IReceiveLocationFormData , ReceiveLocationForm } from "./ReceiveLocationForm" ;
18- import { useAtom , useSetAtom } from "jotai" ;
18+ import { useAtom , useAtomValue , useSetAtom } from "jotai" ;
1919import {
2020 reconciliationMatchProductAtom ,
2121 reconciliationReceiveLocationAtom ,
@@ -55,8 +55,17 @@ export function BoxReconcilationAccordion({
5555 onBoxUndelivered,
5656 onBoxDelivered,
5757} : IBoxReconcilationAccordionProps ) {
58+ const [ reconciliationMatchProductCache , setReconciliationMatchProductCache ] = useAtom (
59+ reconciliationMatchProductAtom ,
60+ ) ;
61+ const cachedReconciliationMatchProduct = useAtomValue ( reconciliationMatchProductAtom ) ;
62+ /** Matching Source Product ID to look up a matching product in the cache store to prefill the form input. */
63+ const matchingProductSourceId = ( shipmentDetail . sourceProduct ?. id as `${number } `) || "0" ;
64+ const isProductIdMatchedInCache = ! ! cachedReconciliationMatchProduct [ matchingProductSourceId ] ;
5865 const isProductAutoMatched = ! ! shipmentDetail ?. autoMatchingTargetProduct ;
59- const [ accordionIndex , setAccordionIndex ] = useState ( isProductAutoMatched ? 1 : 0 ) ;
66+ const [ accordionIndex , setAccordionIndex ] = useState (
67+ isProductIdMatchedInCache ? 0 : isProductAutoMatched ? 1 : 0 ,
68+ ) ;
6069 const [ productManuallyMatched , setProductManuallyMatched ] = useState ( false ) ;
6170 const [ locationSpecified , setLocationSpecified ] = useState ( false ) ;
6271 const [ productFormData , setProductFormData ] = useState < IProductFormData > ( {
@@ -66,9 +75,6 @@ export function BoxReconcilationAccordion({
6675 sizeId : isProductAutoMatched ? parseInt ( shipmentDetail . sourceSize ?. id ?? "0" ) : undefined ,
6776 numberOfItems : shipmentDetail ?. sourceQuantity ?? undefined ,
6877 } ) ;
69- const [ reconciliationMatchProductCache , setReconciliationMatchProductCache ] = useAtom (
70- reconciliationMatchProductAtom ,
71- ) ;
7278 const setReconciliationReceiveLocationCache = useSetAtom ( reconciliationReceiveLocationAtom ) ;
7379 const accordionHeaderColor = isProductAutoMatched || productManuallyMatched ? "#659A7E" : "#000" ;
7480 const accordionHeaderText = productManuallyMatched
@@ -119,7 +125,7 @@ export function BoxReconcilationAccordion({
119125 shipmentDetail = { shipmentDetail }
120126 productAndSizesData = { productAndSizesData }
121127 onBoxUndelivered = { onBoxUndelivered }
122- onSubmitMatchProductsForm = { ( matchedProductsFormData : IMatchProductsFormData ) => {
128+ onSubmitMatchProductsForm = { ( matchedProductsFormData : MatchProductsFormData ) => {
123129 setProductManuallyMatched ( true ) ;
124130 setAccordionIndex ( 1 ) ;
125131
0 commit comments