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 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
19 changes: 16 additions & 3 deletions packages/webapp/src/containers/Task/TaskComplete/StepOne.jsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
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 TaskCompleteStepOne({ history, match, location }) {
// Extracting necessary values from the Redux store using selectors
const {
units: { measurement: system },
country_id,
Expand All @@ -21,24 +22,36 @@ function TaskCompleteStepOne({ history, match, location }) {
const products = useSelector(productsSelector);
const persistedPaths = [`/tasks/${task_id}/complete`];

// Handler for when the user continues to the next step
const onContinue = (data) => {
history.push(persistedPaths[0], location?.state);
};

// Handler for when the user goes back to the previous step
const onGoBack = () => {
history.back();
};

const dispatch = useDispatch();

// Effect to dispatch the getProducts action when the component mounts
useEffect(() => {
dispatch(getProducts());
}, [dispatch]);

// Effect to set persisted paths when the component mounts or when task_id changes
useEffect(() => {
dispatch(
setPersistedPaths([`/tasks/${task_id}/complete`, `/tasks/${task_id}/before_complete`]),
);
}, []);
}, [dispatch, task_id]);

// Generate a unique key based on products length and a timestamp
console.log('Rendering PureCompleteStepOne with key:', JSON.stringify(products));
return (
<HookFormPersistProvider>
<PureCompleteStepOne
key={JSON.stringify(products)}
onContinue={onContinue}
onGoBack={onGoBack}
system={system}
Expand Down
Loading