@@ -63,51 +63,144 @@ function EquipmentDetail() {
6363 dispatch ( fetchEquipmentById ( equipmentId ) ) ;
6464 } , [ dispatch , equipmentId ] ) ;
6565
66- const lastLogRecord = equipment ?. logRecord ?. [ equipment . logRecord . length - 1 ] ;
67- let currentUsage = 'Unknown' ;
66+ const lastLogRecord =
67+ equipment ?. logRecord && equipment . logRecord . length > 0
68+ ? equipment . logRecord [ equipment . logRecord . length - 1 ]
69+ : null ;
70+ let currentUsage = null ;
6871
6972 if ( lastLogRecord ?. type === 'Check In' ) {
7073 currentUsage = 'Checked In' ;
7174 } else if ( lastLogRecord ?. type === 'Check Out' ) {
7275 currentUsage = 'Checked Out' ;
7376 }
7477
78+ const formatValue = value => {
79+ if ( value === 0 ) return 0 ;
80+ if ( value === '' || value === null || value === undefined ) return 'Not Available' ;
81+ return value ;
82+ } ;
83+
84+ const formatPersonName = person => {
85+ if ( ! person ) return null ;
86+ const fullName = `${ person . firstName || '' } ${ person . lastName || '' } ` . trim ( ) ;
87+ return fullName || null ;
88+ } ;
89+
7590 function formatDateString ( dateString ) {
91+ if ( ! dateString ) return 'Not Available' ;
7692 const date = new Date ( dateString ) ;
77- return date . toLocaleDateString ( ) ;
93+ return Number . isNaN ( date . getTime ( ) ) ? 'Not Available' : date . toLocaleDateString ( ) ;
7894 }
7995
8096 const formattedRentedOnDate = formatDateString ( equipment ?. rentedOnDate ) ;
8197 const formattedRentedDueDate = formatDateString ( equipment ?. rentalDueDate ) ;
98+ const latestUpdateRecord =
99+ equipment ?. updateRecord && equipment . updateRecord . length > 0
100+ ? equipment . updateRecord [ equipment . updateRecord . length - 1 ]
101+ : null ;
102+ const latestPurchaseRecord =
103+ equipment ?. purchaseRecord && equipment . purchaseRecord . length > 0
104+ ? equipment . purchaseRecord [ equipment . purchaseRecord . length - 1 ]
105+ : null ;
106+
107+ const formattedLastUpdateDate = formatDateString ( latestUpdateRecord ?. date ) ;
108+
109+ const formatCurrency = amount => {
110+ if ( amount === 0 || amount ) {
111+ const numericAmount = Number ( amount ) ;
112+ if ( Number . isNaN ( numericAmount ) ) return amount ;
113+ return `$${ numericAmount . toLocaleString ( ) } ` ;
114+ }
115+ return null ;
116+ } ;
117+
118+ const invoiceNumber =
119+ latestPurchaseRecord ?. invoiceId ||
120+ latestPurchaseRecord ?. invoiceNo ||
121+ latestPurchaseRecord ?. invoice ;
122+ const purchaseLink =
123+ latestPurchaseRecord ?. purchaseLink ||
124+ equipment ?. purchaseLink ||
125+ equipment ?. itemType ?. purchaseLink ;
126+ const price = formatCurrency ( latestPurchaseRecord ?. price ?? equipment ?. price ?? equipment ?. cost ) ;
127+ const condition = equipment ?. condition || latestUpdateRecord ?. condition ;
128+ const shippingFee = formatCurrency (
129+ latestPurchaseRecord ?. shippingFee ?? equipment ?. shippingFee ?? equipment ?. shippingCost ,
130+ ) ;
131+ const taxes = formatCurrency (
132+ latestPurchaseRecord ?. tax ?? latestPurchaseRecord ?. taxes ?? equipment ?. taxes ,
133+ ) ;
134+ const supplierPhoneNumber =
135+ equipment ?. supplierPhoneNumber ||
136+ latestPurchaseRecord ?. supplierPhoneNumber ||
137+ latestPurchaseRecord ?. supplier ?. phoneNumber ;
138+ const description = equipment ?. itemType ?. description || equipment ?. description ;
139+ const currentStatus = latestUpdateRecord ?. condition ;
140+ const lastUsedPerson = formatPersonName ( latestUpdateRecord ?. createdBy ) ;
141+ const lastUsedTask = latestUpdateRecord ?. task || latestUpdateRecord ?. usedFor ;
142+ const replacementRequested =
143+ typeof latestUpdateRecord ?. replacementRequired === 'boolean'
144+ ? latestUpdateRecord . replacementRequired
145+ ? 'Yes'
146+ : 'No'
147+ : latestUpdateRecord ?. replacementRequired ;
82148
83149 const details = [
84- { label : 'Belongs to Project' , value : equipment ?. project ?. name } ,
85- { label : 'Class' , value : equipment ?. itemType ?. category } ,
86- { label : 'Name' , value : equipment ?. itemType ?. name } ,
87- { label : 'Number' , value : equipment ?. code } ,
88- { label : 'Ownership' , value : equipment ?. purchaseStatus } ,
89- { label : 'Add Date' , value : 'MM - DD - YYYY' } ,
150+ { label : 'Belongs to Project' , value : formatValue ( equipment ?. project ?. name ) } ,
151+ { label : 'Class' , value : formatValue ( equipment ?. itemType ?. category ) } ,
152+ { label : 'Name' , value : formatValue ( equipment ?. itemType ?. name ) } ,
153+ { label : 'Number' , value : formatValue ( equipment ?. code ) } ,
154+ { label : 'Ownership' , value : formatValue ( equipment ?. purchaseStatus ) } ,
155+ { label : 'Add Date' , value : formatDateString ( equipment ?. createdAt ) } ,
90156 // Remove 'Rental Duration' from details if 'Ownership' is 'Purchase'
91- equipment ?. purchaseStatus === 'Purchase ' ? null : { label : 'Rental Duration' } ,
92- { label : 'Current Usage' , value : currentUsage } ,
157+ equipment ?. purchaseStatus === 'Purchased ' ? null : { label : 'Rental Duration' } ,
158+ { label : 'Current Usage' , value : formatValue ( currentUsage ) } ,
93159 { label : 'Dashed Line' } ,
94- { label : 'Input Invoice No or ID' , value : 'No123ABC' } ,
95- { label : 'Price' , value : '$150' } ,
96- { label : 'Add Condition' , value : 'New' } ,
97- { label : 'Shipping Fee' , value : '$25' } ,
98- { label : 'Taxes' , value : '$15' } ,
99- { label : 'Supplier Phone Number' , value : '555-33-3333' } ,
160+ {
161+ label : 'Input Invoice No or ID' ,
162+ value : formatValue ( invoiceNumber ) ,
163+ } ,
164+ {
165+ label : 'Price' ,
166+ value : formatValue ( price ) ,
167+ } ,
168+ {
169+ label : 'Add Condition' ,
170+ value : formatValue ( condition ) ,
171+ } ,
172+ {
173+ label : 'Shipping Fee' ,
174+ value : formatValue ( shippingFee ) ,
175+ } ,
176+ {
177+ label : 'Taxes' ,
178+ value : formatValue ( taxes ) ,
179+ } ,
180+ {
181+ label : 'Supplier Phone Number' ,
182+ value : formatValue ( supplierPhoneNumber ) ,
183+ } ,
100184 {
101185 label : 'Link To Buy/Rent' ,
102- value : 'https://www.homedepot.com/' ,
186+ value : formatValue ( purchaseLink ) ,
187+ } ,
188+ {
189+ label : 'Description' ,
190+ value : formatValue ( description ) ,
103191 } ,
104- { label : 'Description' , value : 'Testing Description' } ,
105192 { label : 'Dashed Line' } ,
106- { label : 'Current Status' , value : 'Tested' } ,
107- { label : 'Last Update Date' , value : '03-01-2024' } ,
108- { label : 'Last Used Person' , value : 'Jae' } ,
109- { label : 'Last Used Task' , value : 'Garden clean up' } ,
110- { label : 'Asked for a replacement?' , value : 'No' } ,
193+ { label : 'Current Status' , value : formatValue ( currentStatus ) } ,
194+ { label : 'Last Update Date' , value : formattedLastUpdateDate } ,
195+ {
196+ label : 'Last Used Person' ,
197+ value : formatValue ( lastUsedPerson ) ,
198+ } ,
199+ { label : 'Last Used Task' , value : formatValue ( lastUsedTask ) } ,
200+ {
201+ label : 'Asked for a replacement?' ,
202+ value : formatValue ( replacementRequested ) ,
203+ } ,
111204 ] ;
112205
113206 const generateKey = ( ) => uuidv4 ( ) ;
@@ -116,9 +209,12 @@ function EquipmentDetail() {
116209 < DetailItem key = { generateKey ( ) } label = { detail . label } value = { detail . value } />
117210 ) ;
118211
119- const renderLinkItem = detail => (
120- < LinkItem key = { generateKey ( ) } label = { detail . label } value = { detail . value } />
121- ) ;
212+ const renderLinkItem = detail => {
213+ if ( detail . value === 'Not Available' ) {
214+ return renderDetailItem ( detail ) ;
215+ }
216+ return < LinkItem key = { generateKey ( ) } label = { detail . label } value = { detail . value } /> ;
217+ } ;
122218
123219 const renderRentalDurationItem = detail => (
124220 < RentalDurationItem
@@ -129,14 +225,19 @@ function EquipmentDetail() {
129225 />
130226 ) ;
131227
132- const renderDescriptionItem = detail => (
133- < DescriptionItem
134- key = { generateKey ( ) }
135- label = { detail . label }
136- value = { detail . value }
137- // title={equipment?.itemType.name}
138- />
139- ) ;
228+ const renderDescriptionItem = detail => {
229+ if ( detail . value === 'Not Available' ) {
230+ return renderDetailItem ( detail ) ;
231+ }
232+ return (
233+ < DescriptionItem
234+ key = { generateKey ( ) }
235+ label = { detail . label }
236+ value = { detail . value }
237+ title = { equipment ?. itemType ?. name || 'Description' }
238+ />
239+ ) ;
240+ } ;
140241
141242 const renderDashedLineItem = detail => (
142243 < DashedLineItem key = { generateKey ( ) } label = { detail . label } />
@@ -165,7 +266,11 @@ function EquipmentDetail() {
165266 </ header >
166267 < main className = { styles . equipmentDetailPageContent } >
167268 < p >
168- < img src = { equipment ?. imageUrl } alt = "" className = { styles . equipmentDetailPageImage } />
269+ < img
270+ src = { equipment ?. imageUrl }
271+ alt = { equipment ?. itemType ?. name || 'Equipment image' }
272+ className = { styles . equipmentDetailPageImage }
273+ />
169274 </ p >
170275 { details . filter ( Boolean ) . map ( renderDetails ) }
171276 < Button
0 commit comments