Skip to content

Commit

Permalink
Reset TimeSlotSelector value when changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre-LHOSTE committed Jun 19, 2024
1 parent 0f46e67 commit b276b20
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/navigation/store/NewDeliveryForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ function NewDelivery(props) {
const backgroundContainerColor = useBackgroundContainerColor();
const backgroundColor = useBackgroundColor();
const backgroundHighlightColor = useBackgroundHighlightColor();
const [selectValue, setSelectValue] = React.useState(null);

const inputStyles = {
backgroundColor: backgroundContainerColor,
Expand Down Expand Up @@ -66,6 +67,8 @@ function NewDelivery(props) {
props.loadTimeSlotChoices(
props.timeSlots.find(ts => ts.name === selectedTimeSlot),
);
} else {
setSelectValue(null);
}
}, [selectedTimeSlot, props.loadTimeSlotChoices, props.timeSlots]);

Check failure on line 73 in src/navigation/store/NewDeliveryForm.js

View workflow job for this annotation

GitHub Actions / Basic tests

React Hook useEffect has a missing dependency: 'props'. Either include it or remove the dependency array. However, 'props' will change when *any* prop changes, so the preferred fix is to destructure the 'props' object outside of the useEffect call and refer to those specific props inside useEffect

Check failure on line 73 in src/navigation/store/NewDeliveryForm.js

View workflow job for this annotation

GitHub Actions / Basic tests

React Hook useEffect has a missing dependency: 'props'. Either include it or remove the dependency array. However, 'props' will change when *any* prop changes, so the preferred fix is to destructure the 'props' object outside of the useEffect call and refer to those specific props inside useEffect

Expand Down Expand Up @@ -309,6 +312,8 @@ function NewDelivery(props) {
</View>
{props.hasTimeSlot && (
<TimeSlotSelector
selectValue={selectValue}
setSelectValue={setSelectValue}
errors={errors}
touched={touched}
setFieldValue={setFieldValue}
Expand Down
4 changes: 4 additions & 0 deletions src/navigation/store/components/TimeSlotSelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ export default function TimeSlotSelector({
timeSlots,
choices,
selectedTimeSlot,
selectValue,
setSelectValue,
}) {
const { t } = useTranslation();
const primaryColor = usePrimaryColor();
Expand Down Expand Up @@ -132,6 +134,7 @@ export default function TimeSlotSelector({
if (!value) return;
setFieldValue('timeSlot', value.key);
setFieldTouched('timeSlot');
setSelectValue(value);
}}
items={choices.map(
choice => (choice = { value: choice.value, label: choice.label }),
Expand All @@ -140,6 +143,7 @@ export default function TimeSlotSelector({
label: t('STORE_NEW_DELIVERY_SELECT_TIME_SLOT'),
value: null,
}}
value={selectValue}
/>
{errors.timeSlot && touched.timeSlot && (
<Text note style={styles.errorText}>
Expand Down

0 comments on commit b276b20

Please sign in to comment.