Skip to content

Commit

Permalink
feat: when global-state prod-id is updated it substitutes the join-pr…
Browse files Browse the repository at this point in the history
…od-id and reset on join-click
  • Loading branch information
malmen237 authored and birme committed Jul 12, 2024
1 parent dd554ca commit b5ce747
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/components/landing-page/join-production.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export const JoinProduction = ({ preSelected }: TProps) => {
},
});

const [{ devices }, dispatch] = useGlobalState();
const [{ devices, selectedProductionId }, dispatch] = useGlobalState();

const {
error: productionFetchError,
Expand Down Expand Up @@ -96,6 +96,19 @@ export const JoinProduction = ({ preSelected }: TProps) => {
}
}, [setValue]);

// If user selects a production from the productionlist
useEffect(() => {
if (
selectedProductionId &&
selectedProductionId !== joinProductionId?.toString()
) {
reset({
productionId: `${selectedProductionId}`,
});
setJoinProductionId(parseInt(selectedProductionId, 10));
}
}, [joinProductionId, reset, selectedProductionId]);

const { onChange, onBlur, name, ref } = register("productionId", {
required: "Production ID is required",
min: 1,
Expand All @@ -110,6 +123,10 @@ export const JoinProduction = ({ preSelected }: TProps) => {
type: "UPDATE_JOIN_PRODUCTION_OPTIONS",
payload,
});
dispatch({
type: "SELECT_PRODUCTION_ID",
payload: null,
});
// TODO remove
console.log(payload);
};
Expand Down

0 comments on commit b5ce747

Please sign in to comment.