Skip to content

Commit 7d83c51

Browse files
committed
merge conflicts
2 parents 1dc6765 + 17d4904 commit 7d83c51

File tree

4 files changed

+59
-4
lines changed

4 files changed

+59
-4
lines changed

.editorconfig

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# EditorConfig is awesome: https://EditorConfig.org
2+
# This file was generated using "EditorConfig for VS Code"
3+
4+
# top-most EditorConfig file
5+
root = true
6+
7+
[*]
8+
indent_style = space
9+
indent_size = 2
10+
end_of_line = lf
11+
charset = utf-8
12+
trim_trailing_whitespace = true
13+
insert_final_newline = true

pages/requests/new/[ware].js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,16 @@ import {
1919
configureErrors,
2020
createRequest,
2121
requestFormHeaderBg,
22+
sendRequestToVendor,
2223
useInitializeRequest,
2324
} from '../../../utils'
2425

2526
const NewRequest = () => {
2627
const router = useRouter()
2728
const { data: session } = useSession()
29+
const accessToken = session?.accessToken
2830
const wareID = router.query.id
29-
const { dynamicForm, isLoadingInitialRequest, isInitialRequestError } = useInitializeRequest(wareID, session?.accessToken)
31+
const { dynamicForm, isLoadingInitialRequest, isInitialRequestError } = useInitializeRequest(wareID, accessToken)
3032
const oneWeekFromNow = addDays((new Date()), 7).toISOString().slice(0, 10)
3133
const initialFormData = { 'suppliers_identified': 'Yes' }
3234
const initialState = {
@@ -97,10 +99,13 @@ const NewRequest = () => {
9799
const { data, error } = await createRequest({
98100
dynamicFormData: { name: dynamicForm.name, formData, ...requestForm },
99101
wareID,
100-
accessToken: session?.accessToken,
102+
accessToken,
101103
})
102104
if (error) return setCreateRequestError(error)
103105

106+
const sentToVendor = await sendRequestToVendor(data.id, accessToken)
107+
if (sentToVendor.error) return setCreateRequestError(sentToVendor.error)
108+
104109
setCreatedRequestUUID(data.uuid)
105110
}
106111

utils/api/base.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,21 @@ export const posting = async (url, data, token) => {
2929
return { success: false, error, requestID: undefined }
3030
}
3131
}
32+
33+
export const updating = async (url, data, token) => {
34+
try {
35+
const response = await api.put(url, data, { headers: defaultHeaders(token) })
36+
37+
return {
38+
data: response.data,
39+
error: false,
40+
}
41+
} catch (error) {
42+
// TODO(alishaevn): handle the error when sentry is set up
43+
console.error(`The following error occurred when trying to update data:`, error)
44+
return {
45+
data: undefined,
46+
error,
47+
}
48+
}
49+
}

utils/api/requests.js

Lines changed: 21 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, fetcher } from './base'
10+
import { fetcher, posting, updating } from './base'
1111

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

216216
if (data && dynamicFormData.attachments) {
217+
/**
218+
* TODO(alishaevn): I'm not sure why, but sometimes our data does not have the "quoted_ware_refs" property on it.
219+
* a search for the request in postman however, returns the property. we should find the underlying commonality on
220+
* requests that don't return the value so we can fix it. (ref: https://github.com/scientist-softserv/webstore/issues/252)
221+
*/
222+
let quotedWareID = data.quoted_ware_refs?.[0]?.id
223+
if (!quotedWareID) {
224+
// we have to explicity use fetcher because "useOneRequest" is a hook
225+
const res = await fetcher(`/quote_groups/${data.id}.json`, accessToken)
226+
quotedWareID = res.quoted_ware_refs?.[0]?.id
227+
}
228+
217229
const attachedFiles = await createMessageOrFile({
218230
accessToken,
219231
id: data.id,
220232
files: dynamicFormData.attachments,
221-
quotedWareID: data.quoted_ware_refs?.[0].id,
233+
quotedWareID,
222234
})
223235

224236
if (attachedFiles.error) {
@@ -230,3 +242,10 @@ export const createRequest = async ({ dynamicFormData, wareID, accessToken }) =>
230242
return { data, error }
231243
/* eslint-enable camelcase */
232244
}
245+
246+
/** PUT METHODS */
247+
export const sendRequestToVendor = async (requestID, accessToken) => {
248+
const { data, error } = await updating(`/quote_groups/${requestID}/send_to_vendors.json`, {}, accessToken)
249+
250+
return { data, error }
251+
}

0 commit comments

Comments
 (0)