Skip to content

Commit 4082e7f

Browse files
committed
add a fallback for "data.quoted_ware_refs?.[0]?.id" when creating a request with attachments
1 parent 979f51f commit 4082e7f

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

utils/api/requests.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
configureMessages,
88
configureRequests,
99
} from './configurations'
10-
import { posting } from './base'
10+
import { fetcher, posting } from './base'
1111

1212
/** GET METHODS */
1313
export const useAllRequests = (accessToken) => {
@@ -193,11 +193,23 @@ export const createRequest = async ({ dynamicFormData, wareID, accessToken }) =>
193193
let { data, error } = await posting(`/wares/${wareID}/quote_groups.json`, { pg_quote_group }, accessToken)
194194

195195
if (data && dynamicFormData.attachments) {
196+
/**
197+
* TODO(alishaevn): I'm not sure why, but sometimes our data does not have the "quoted_ware_refs" property on it.
198+
* a search for the request in postman however, returns the property. we should find the underlying commonality on
199+
* requests that don't return the value so we can fix it.
200+
*/
201+
let quotedWareID = data.quoted_ware_refs?.[0]?.id
202+
if (!quotedWareID) {
203+
// we have to explicity use fetcher because "useOneRequest" is a hook
204+
const res = await fetcher(`/quote_groups/${data.id}.json`, accessToken)
205+
quotedWareID = res.quoted_ware_refs?.[0]?.id
206+
}
207+
196208
const attachedFiles = await createMessageOrFile({
197209
accessToken,
198210
id: data.id,
199211
files: dynamicFormData.attachments,
200-
quotedWareID: data.quoted_ware_refs?.[0].id,
212+
quotedWareID,
201213
})
202214

203215
if (attachedFiles.error) {

0 commit comments

Comments
 (0)