Skip to content

Commit

Permalink
issue #202: confirmation field
Browse files Browse the repository at this point in the history
  • Loading branch information
k-allagbe committed Jan 14, 2025
1 parent 7a1dfde commit e929aeb
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/app/label-data-confirmation/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ const QuantityChips = React.forwardRef<HTMLDivElement, QuantityChipsProps>(
QuantityChips.displayName = "QuantityChips";

const LabelDataConfirmationPage = () => {
const { labelData } = useLabelDataStore();
const labelData = useLabelDataStore((state) => state.labelData);
const updateConfirmed = useLabelDataStore((state) => state.updateConfirmed);
const { uploadedFiles } = useUploadedFilesStore();
const imageFiles = uploadedFiles.map((file) => file.getFile());
const { t } = useTranslation("labelDataValidator");
Expand Down Expand Up @@ -447,7 +448,12 @@ const LabelDataConfirmationPage = () => {
{/* Acknowledgment Checkbox */}
<FormGroup className="flex items-center justify-center gap-2">
<FormControlLabel
control={<Checkbox />}
control={
<Checkbox
checked={labelData?.confirmed}
onChange={(event) => updateConfirmed(event.target.checked)}
/>
}
label={
<Typography variant="body2" className="!font-bold">
I acknowledge that the data is accurate.
Expand Down
11 changes: 11 additions & 0 deletions src/stores/labelDataStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,23 @@ interface LabelDataState {
labelData: LabelData | null;
setLabelData: (newData: LabelData) => void;
resetLabelData: () => void;
updateConfirmed: (isConfirmed: boolean) => void;
}

const useLabelDataStore = create<LabelDataState>((set) => ({
labelData: VERIFIED_LABEL_DATA,
setLabelData: (newData) => set({ labelData: newData }),
resetLabelData: () => set({ labelData: null }),
updateConfirmed: (isConfirmed) =>
set((state) => {
if (!state.labelData) return state;
return {
labelData: {
...state.labelData,
confirmed: isConfirmed,
},
};
}),
}));

export default useLabelDataStore;
2 changes: 2 additions & 0 deletions src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ export type LabelData = {
instructions: BilingualField[];
guaranteedAnalysis: GuaranteedAnalysis;
ingredients: BilingualField[];
confirmed: boolean;
};

export const DEFAULT_LABEL_DATA: LabelData = {
Expand All @@ -194,6 +195,7 @@ export const DEFAULT_LABEL_DATA: LabelData = {
instructions: [DEFAULT_BILINGUAL_FIELD],
guaranteedAnalysis: DEFAULT_GUARANTEED_ANALYSIS,
ingredients: [FULL_BILINGUAL_FIELD],
confirmed: false,
};

// Form
Expand Down

0 comments on commit e929aeb

Please sign in to comment.