Skip to content

Commit

Permalink
able to create requests again
Browse files Browse the repository at this point in the history
when a description is not provided, the validations fail. we are now
passing the `data_str` and `dynamic_forms_to_embed` properties when
creating a new request as their presence allow the validations to pass,
even in the absence of a description.

ref:
- https://github.com/assaydepot/rx/blob/main/app/models/pg/quote_group.rb#L778-L781
- https://assaydepot.slack.com/archives/CF6490Y80/p1705098558758609?thread_ts=1704996805.983419&cid=CF6490Y80
  • Loading branch information
alishaevn committed Jan 19, 2024
1 parent feb9e18 commit c3f0256
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
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

0 comments on commit c3f0256

Please sign in to comment.