Skip to content

Commit 3b8978f

Browse files
authored
feat: add field to modify round for each step in settings (#534)
1 parent 2fda47d commit 3b8978f

File tree

1 file changed

+40
-2
lines changed

1 file changed

+40
-2
lines changed

src/modules/settings/activity/steps/StepEditDialog.tsx

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,33 @@ const StepEditDialog: FC<StepEditDialogProps> = ({
3333
}) => {
3434
// eslint-disable-next-line @typescript-eslint/no-unused-vars
3535
const { t } = useTranslation('translations');
36-
const { type, time, evaluationType, evaluationParameters, resultsType } =
37-
step;
36+
const {
37+
type,
38+
time,
39+
evaluationType,
40+
evaluationParameters,
41+
resultsType,
42+
round,
43+
} = step;
3844

3945
const [timeBuffer, setTimeBuffer] = useState<string>('0');
4046
const [errorTime, setErrorTime] = useState(false);
4147

48+
const [roundBuffer, setRoundBuffer] = useState<string>('0');
49+
const [errorRound, setErrorRound] = useState(false);
50+
4251
useEffect(() => {
4352
if (time) {
4453
setTimeBuffer(time.toString(10));
4554
}
4655
}, [time]);
4756

57+
useEffect(() => {
58+
if (round) {
59+
setRoundBuffer(round.toString(10));
60+
}
61+
}, [round]);
62+
4863
const renderStepDescription = (activityType: ActivityType): string => {
4964
// TODO: Translate
5065
switch (activityType) {
@@ -133,8 +148,24 @@ const StepEditDialog: FC<StepEditDialogProps> = ({
133148
});
134149
}
135150
};
151+
152+
const handleRoundChange = (event: ChangeEvent<HTMLInputElement>): void => {
153+
const newRoundStr = event.target.value;
154+
setRoundBuffer(newRoundStr);
155+
const newRound = parseInt(newRoundStr, 10);
156+
if (Number.isNaN(newRound)) {
157+
setErrorRound(true);
158+
} else {
159+
setErrorRound(false);
160+
onChange({
161+
...step,
162+
round: newRound,
163+
});
164+
}
165+
};
136166
return (
137167
<Dialog open={open}>
168+
{/* TODO: Translate */}
138169
<DialogTitle>Edit the step</DialogTitle>
139170
<DialogContent sx={{ p: 1 }}>
140171
<Select value={type} label="Type" onChange={handleChangeType}>
@@ -150,6 +181,13 @@ const StepEditDialog: FC<StepEditDialogProps> = ({
150181
onChange={handleTimeChange}
151182
error={errorTime}
152183
/>
184+
<TextField
185+
// TODO: Translate
186+
label="Round"
187+
value={roundBuffer}
188+
onChange={handleRoundChange}
189+
error={errorRound}
190+
/>
153191
<DialogContentText>{renderStepDescription(type)}</DialogContentText>
154192
{renderActivitySettings(type)}
155193
</DialogContent>

0 commit comments

Comments
 (0)