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

This change will show the created product during the completion of a Soil Amendment, Clean or Pest Contol task. #3211

Open
wants to merge 4 commits into
base: integration
Choose a base branch
from
Open
Changes from 2 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
17 changes: 14 additions & 3 deletions packages/webapp/src/containers/Task/TaskComplete/StepOne.jsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import React, { useEffect } from 'react';
import PureCompleteStepOne from '../../../components/Task/TaskComplete/StepOne';
import { useSelector, shallowEqual } from 'react-redux';
import { useSelector, shallowEqual, useDispatch } from 'react-redux';
import { userFarmSelector } from '../../userFarmSlice';
import { HookFormPersistProvider } from '../../hooks/useHookFormPersist/HookFormPersistProvider';
import { taskWithProductSelector } from '../../taskSlice';
import { productsSelector } from '../../productSlice';
import { certifierSurveySelector } from '../../OrganicCertifierSurvey/slice';
import { useDispatch } from 'react-redux';
import { setPersistedPaths } from '../../hooks/useHookFormPersist/hookFormPersistSlice';
import { getProducts } from '../saga';

function generateProductsKey(products) {
return products.map((product) => `${product.product_id}-${product.supplier}`).join('-');
Copy link
Collaborator

@SayakaOno SayakaOno May 24, 2024

Choose a reason for hiding this comment

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

I don't think this solution is maintainable or scalable. We would need to update this function every time a new field is added, like NPK.
One way to go about it is to include all fields in the key using Object.values(product).join('-');, but the key will be very long. I would suggest you go in a different direction.

We can discuss this in dev standup next week!

}

function TaskCompleteStepOne({ history, match, location }) {
const {
Expand All @@ -30,15 +34,22 @@ function TaskCompleteStepOne({ history, match, location }) {
};

const dispatch = useDispatch();
useEffect(() => {
dispatch(getProducts());
}, [dispatch]);

useEffect(() => {
dispatch(
setPersistedPaths([`/tasks/${task_id}/complete`, `/tasks/${task_id}/before_complete`]),
);
}, []);
}, [dispatch, task_id]);

const productsKey = generateProductsKey(products);

return (
<HookFormPersistProvider>
<PureCompleteStepOne
key={productsKey}
onContinue={onContinue}
onGoBack={onGoBack}
system={system}
Expand Down
Loading