Skip to content

OBPIH-6111 Add pricing section with inputs#4517

Merged
awalkowiak merged 20 commits intofeature/product-supplier-list-redesignfrom
OBPIH-6111-add-pricing-section-with-inputs
Feb 26, 2024
Merged

OBPIH-6111 Add pricing section with inputs#4517
awalkowiak merged 20 commits intofeature/product-supplier-list-redesignfrom
OBPIH-6111-add-pricing-section-with-inputs

Conversation

@drodzewicz
Copy link
Collaborator

No description provided.


export default {
getCurrenciesOptions: () => apiClient.get(CURRENCIES_OPTIONS),
getUnitOfMeasureOptions: (type) => apiClient.get(UNIT_OF_MEASURE_OPTIONS, {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't it follow our current convention with passing config, as params is not the only property we can pass to axios?

const dispatch = useDispatch();

const {
quantityUoM,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpicky, but let's name it as quantityUom and change the UoMType to UomType, as imho it's more JS' way of naming things.


useEffect(() => {
dispatch(fetchQuantityUoM());
}, []);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think lines 13-23 should belong to a custom hook, maybe usePackageSpecification.js and just return quantityUom from it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You actually have a point about creating a separate hook for that chunk of code, but I think that this should not be a hook directly connected to a subsection, but an options hook, hear me out...

So currently in out app there are many instances where we do the exact thing as I did above for quantityUom.
We fetch these options, store them in redux and access them usually in the same component

So I feel like it should be a pattern for us that we can follow. I suggest creating hooks for this specific case where we dispatch(fetch...) and return this from a selector in that custom hook.

I am unsure about the naming (as always) but my initial suggestion is to follow a naming for hook use....Options and the directory option-data.

What do you think?
@kchelstowski @alannadolny

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@drodzewicz good point. I think we could name it like useOptionsFetch, we could pass there the functions:
useOptionsFetch([fetchQuantityUom, ...])
and it the hook itself just map through this list and run the functions.
Although please, remember about adding the AbortController, and also, as a dependency let's add the locale - recently we've forgotten to add it as a dependency, but let's reduce the amount of "translations bugs" that will come up when the crowdin is invoked again.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we want to create an abstract/generic useOptionsFetch hook, I was thinking about a separate options hook for every other case like I pushed the example for QuantityUnitOfMeasure.
So some example are hooks like useRatingTypeCodeOptions, useInvoiceStatusOptions etc... that could potentially look the same as useQuantityUnitOfMeasureOptions

My reasoning for that is that I want to handle the fetch and a value return in the same hook, and handling a value return would be a little complicated to do in a generic way.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I misunderstood the intentions.
What I've been thinking about was a generic fetch hook, to which we could pass fetch functions and potentially the dependency array.
I don't think we need to return the options from the hook directly if they are from Redux, since we have a global access for them, but we could also combine our ideas and leave your hook and create one more hook that would be called inside yours, just for fetching stuff (useEffect + dispatch). Let's wait for others to give their opinion on that one.

setValue('eachPrice', '');
}
},
[packagePrice, packageSize]);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you decide to create the usePackageSpecification hook, I think this could be placed there, but you would have to return the setValue from this hook and pass it to the PricingSection from ProductSupplierFormMain component.
But on the other hand I don't mind keeping it there - I just think that such calculations that are strictly connected to a specific section, should be handled in this section's hook.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm 50-50 about this one, so I'll let you guys decide.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I see what you mean but I feel like in this case, it is alright to calculate this value in our main hook for product sources. I don't think it adds any complexity to the readability of the code since it is the same place where we transform/manipulate the form data for the API call, but that's my opinion.

.coerce
.number({ required_error: 'Package size is required' })
.gte(1)
.nullable(),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if it's on one hand required, why is it nullable additionally?

}));

useEffect(() => {
dispatch(fetchQuantityUoM());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should add AbortController

@drodzewicz drodzewicz force-pushed the OBPIH-6111-add-pricing-section-with-inputs branch from f2e2cf6 to 022f181 Compare February 26, 2024 11:00
@drodzewicz drodzewicz force-pushed the OBPIH-6111-add-pricing-section-with-inputs branch from 022f181 to f3e6917 Compare February 26, 2024 11:20
@awalkowiak awalkowiak merged commit 8541b3f into feature/product-supplier-list-redesign Feb 26, 2024
@awalkowiak awalkowiak deleted the OBPIH-6111-add-pricing-section-with-inputs branch February 26, 2024 14:21
awalkowiak pushed a commit that referenced this pull request Mar 12, 2024
* OBPIH-6111 Added Section and subsection wrappers for pricing

* OBPIH-6111 Added Package Specification subsection

* OBPIH-6111 Added Fixed price subsection

* OBPIH-6111 Added reducer for UoMs

* OBPIH-6111 Refactor reducer for UoM

* OBPIH-6111 Remove old currency reducer and move it to UoM

* OBPIH-6111 Modified textInput component to handle number decimal formatting

* OBPIH-6111 Fxied Fixed price section validation schema

* OBPIH-6111 Update Pricing section numeric input types and add missing tooltip on input

* OBPIH-6111 Compute eachPrice value from packagePrice and packageSize

* OBPIH-6111 Fix Checkbox component

* OBPIH-6111 Added additional validation to numeric fields

* OBPIH-6111 rename field to uomCode

* OBPIH-6111 Fix datepicker component

* OBPIH-6111 Fix Number Input validation

* OBPIH-6111 rename Unit Of measure variables

* OBPIH-6111 rename minimum order quantity

* OBPIH-6111 Create a custom hook for fetching and accesing PreferenceTypeOptions

* OBPIH-6111 Created a generic useoptionsFetch hook to handle option fetches

* OBPIH-6111 rename properties
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants