7
7
configureMessages ,
8
8
configureRequests ,
9
9
} from './configurations'
10
- import { posting } from './base'
10
+ import { fetcher , posting , updating } from './base'
11
11
12
12
/** GET METHODS */
13
13
export const useAllRequests = ( accessToken ) => {
@@ -193,11 +193,23 @@ export const createRequest = async ({ dynamicFormData, wareID, accessToken }) =>
193
193
let { data, error } = await posting ( `/wares/${ wareID } /quote_groups.json` , { pg_quote_group } , accessToken )
194
194
195
195
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. (ref: https://github.com/scientist-softserv/webstore/issues/252)
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
+
196
208
const attachedFiles = await createMessageOrFile ( {
197
209
accessToken,
198
210
id : data . id ,
199
211
files : dynamicFormData . attachments ,
200
- quotedWareID : data . quoted_ware_refs ?. [ 0 ] . id ,
212
+ quotedWareID,
201
213
} )
202
214
203
215
if ( attachedFiles . error ) {
@@ -209,3 +221,10 @@ export const createRequest = async ({ dynamicFormData, wareID, accessToken }) =>
209
221
return { data, error }
210
222
/* eslint-enable camelcase */
211
223
}
224
+
225
+ /** PUT METHODS */
226
+ export const sendRequestToVendor = async ( requestID , accessToken ) => {
227
+ const { data, error } = await updating ( `/quote_groups/${ requestID } /send_to_vendors.json` , { } , accessToken )
228
+
229
+ return { data, error }
230
+ }
0 commit comments