Skip to content

Commit

Permalink
Allow duration to be entered manually
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertOstermann committed Nov 2, 2023
1 parent f8820fa commit 17e5633
Showing 1 changed file with 14 additions and 34 deletions.
48 changes: 14 additions & 34 deletions client/src/components/pages/coaches/Entry/Entry.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default function CoachEntry() {
const [user, setUser] = useState<UserModel | undefined>();
const [isLoading, setIsLoading] = useState(false);
const [activity, setActivity] = useState<number>(ActivityTypes.game.id);
const [duration, setDuration] = useState<number>(15);
const [duration, setDuration] = useState<number | string>(15);
const [date, setDate] = useState<Date>(
new Date(new Date().setHours(0, 0, 0, 0))
);
Expand All @@ -50,7 +50,7 @@ export default function CoachEntry() {
mutationFn: () => EntryRequests.createEntry(token, {
authId: user?.authId,
activityType: activity,
activityDuration: duration,
activityDuration: typeof duration === "number" ? duration : 0,
activityDate: date,
}),
onSuccess: () => {
Expand Down Expand Up @@ -105,32 +105,6 @@ export default function CoachEntry() {
);
};

const durationOptions = () => {
const options = [];
let currentDuration = 15;
const maxDuration = 180;

let index = 0;
while (currentDuration <= maxDuration) {
currentDuration += 15;
const hours = Math.floor(currentDuration / 60);
const hoursString =
hours > 0 ? (hours === 1 ? `${hours} Hour ` : `${hours} Hours `) : "";
const minutes = currentDuration % 60;
const minutesString = `${minutes} minutes`;

options.push(
<option
key={`duration-${index}`}
value={currentDuration}
>{`${hoursString}${minutesString}`}</option>
);
index++;
}

return options;
};

const submitButton = () => {
return (
<Navbar
Expand Down Expand Up @@ -203,12 +177,18 @@ export default function CoachEntry() {
</Form.Select>
</Form.Group>
<Form.Group className={styles.formGroup}>
<Form.Label>Duration</Form.Label>
<Form.Select
onChange={(event) => setDuration(parseInt(event.target.value))}
>
{durationOptions()}
</Form.Select>
<Form.Label>Duration (minutes)</Form.Label>
<Form.Control
type="number"
placeholder="Duration in minutes"
isInvalid={duration < 0}
value={duration ?? ""}
onChange={(event) => {
const number = parseInt(event.target.value);
if (isNaN(number)) setDuration("");
else setDuration(parseInt(event.target.value))
}}
/>
</Form.Group>
</Form>
{submitButton()}
Expand Down

0 comments on commit 17e5633

Please sign in to comment.