Skip to content

Commit c78dd39

Browse files
committed
if adding an attachment to a request upon creation results in an error, pass that error to the request show page and handle it
1 parent a63d4d9 commit c78dd39

File tree

2 files changed

+45
-6
lines changed

2 files changed

+45
-6
lines changed

pages/requests/[uuid].js

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const Request = ({ session }) => {
3333
* as a dynamically routed file, the router query will always consist of a "key: value" pair that's determined by the name of
3434
* the file (key) and path string (value). additional query properties may also exist if they were explicitly passed.
3535
*/
36-
const { uuid } = router.query
36+
const { createRequestError, uuid } = router.query
3737
const accessToken = session?.accessToken
3838
const { request, isLoadingRequest, isRequestError } = useOneRequest(uuid, accessToken)
3939
const { allSOWs, isLoadingSOWs, isSOWError } = useAllSOWs(uuid, request?.identifier, accessToken)
@@ -78,6 +78,33 @@ const Request = ({ session }) => {
7878
)
7979
}
8080

81+
// this error is a result of creating the request
82+
if (createRequestError) {
83+
// TODO(alishaevn): how to handle a "sent to vendor" error?
84+
const attachmentError = JSON.parse(createRequestError).config.url.includes('notes')
85+
86+
return (
87+
<Notice
88+
alert={attachmentError &&
89+
{
90+
body: ['Your attachment failed. Please visit your request and try again from the "View Files" tab.'],
91+
title: 'Attachment Error',
92+
variant: 'info',
93+
}
94+
}
95+
dismissible={false}
96+
withBackButton={true}
97+
buttonProps={attachmentError &&
98+
{
99+
onClick: () => router.push({ pathname: `/requests/${uuid}` }),
100+
text: 'Click to view your request.',
101+
}
102+
}
103+
/>
104+
)
105+
}
106+
107+
// this error is a result of getting the request or its related data
81108
if (isError) {
82109
return (
83110
<Notice

pages/requests/new/[ware].js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,22 +99,34 @@ const NewRequest = ({ session }) => {
9999
wareID,
100100
accessToken,
101101
})
102-
if (error) return setCreateRequestError(error)
102+
// if we have data AND an error, the request was created, but the attachments failed
103+
// in that case, we still need to send the request to the vendor
104+
if (error && !data) {
105+
setFormSubmitting(false)
106+
setCreateRequestError(error)
107+
return
108+
} else if (error) {
109+
setCreateRequestError(error)
110+
}
103111

104112
const sentToVendor = await sendRequestToVendor(data.id, accessToken)
105-
if (sentToVendor.error) return setCreateRequestError(sentToVendor.error)
113+
if (sentToVendor.error) {
114+
setFormSubmitting(false)
115+
setCreateRequestError(sentToVendor.error)
116+
}
106117

107118
setCreatedRequestUUID(data.uuid)
108119
}
109120

110121
useEffect(() => {
111122
if (createdRequestUUID) {
112123
router.push({
113-
pathname: `/requests/${createdRequestUUID}`
114-
})
124+
pathname: `/requests/${createdRequestUUID}`,
125+
query: { createRequestError: JSON.stringify(createRequestError) },
126+
}, `/requests/${createdRequestUUID}`)
115127
}
116128
// eslint-disable-next-line react-hooks/exhaustive-deps
117-
}, [createdRequestUUID])
129+
}, [createdRequestUUID, createRequestError])
118130

119131
// TODO(alishaevn): use react bs placeholder component
120132
if (isLoadingInitialRequest || !wareID || formSubmitting) return <Loading wrapperClass='item-page mt-5' />

0 commit comments

Comments
 (0)