Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

34 unable to create requests #35

Merged
merged 1 commit into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pages/requests/new/[ware].js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ const NewRequest = ({ session }) => {
if (requestForm.billingSameAsShipping === true) Object.assign(requestForm.billing, requestForm.shipping)

const { data, error } = await createRequest({
dynamicFormData: { name: dynamicForm.name, formData, ...requestForm },
dynamicFormData: { ...dynamicForm, formData, ...requestForm },
wareID,
accessToken,
})
Expand Down
11 changes: 9 additions & 2 deletions utils/api/requests.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,17 @@ export const useFiles = (id, accessToken) => {
}
}


export const useInitializeRequest = (id, accessToken) => {
const { data, error } = useSWR(accessToken ? [`/wares/${id}/quote_groups/new.json`, accessToken] : null)
let dynamicForm = { name: data?.name }
let dynamicFormInfo = data?.dynamic_forms[0]

if (dynamicFormInfo) {
dynamicForm = {
...dynamicForm,
orderPriority: dynamicFormInfo.order_priority || 1,
parentDynamicFormId: dynamicFormInfo.parent_dynamic_form_id,
}
const defaultSchema = dynamicFormInfo.schema
const defaultOptions = dynamicFormInfo.options
const schema = configureDynamicFormSchema(defaultSchema)
Expand Down Expand Up @@ -225,11 +229,14 @@ export const createRequest = async ({ dynamicFormData, wareID, accessToken }) =>
})

const pg_quote_group = {
...formData,
...sharedRequestData,
name: dynamicFormData.name,
suppliers_identified: 'Yes',
description: requestDescription,
data_str: JSON.stringify(formData),
dynamic_forms_to_embed: [
{ id: dynamicFormData.parentDynamicFormId, order_priority: dynamicFormData.orderPriority }
],
no_proposed_deadline: dynamicFormData.proposedDeadline ? false : true,
timeline: requestTimeline,
}
Expand Down
Loading