-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
135 additions
and
59 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
app/(protected)/live/workouts/[workoutId]/exerciseSetWidget/ExerciseInputModal.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { useState } from "react"; | ||
import ClientModal from "@/components/ClientModal"; | ||
import SolidButton from "@/components/buttons/SolidButton"; | ||
import GhostButton from "@/components/buttons/GhostButton"; | ||
import Input from "@/components/forms/Input"; | ||
import Form from "@/components/forms/Form"; | ||
import NumericInput from "@/components/forms/NumericInput"; | ||
|
||
type ExerciseInputModalProps = { | ||
onSubmit: (e: ExerciseInputModalState) => void; | ||
exerciseTypeName: string; | ||
handleClose?: () => void | ||
initalValues?: { | ||
weight?: number; | ||
reps?: number; | ||
} | ||
} | ||
|
||
export type ExerciseInputModalState = { | ||
weight: number | ||
reps: number | ||
} | ||
|
||
export default function ExerciseInputModal({onSubmit, exerciseTypeName, handleClose, initalValues }: ExerciseInputModalProps) { | ||
const [weight, setWeight] = useState<number | undefined>(initalValues?.weight); | ||
const [reps, setReps] = useState<number | undefined>(initalValues?.reps); | ||
const buttonEnabled = (weight != null) && (reps != null); | ||
|
||
return ( | ||
<ClientModal handleClose={ handleClose }> | ||
<Form title={`${exerciseTypeName}`} onSubmit={() => {weight && reps && onSubmit({weight, reps})}}> | ||
<NumericInput label="Weight" htmlFor="weight" type="number" step="0.5" id="weight" name="Weight" placeholder="9000" value={weight} onValueUpdate={setWeight} /> | ||
<NumericInput label="Reps" htmlFor="reps" type="number" step="1" id="reps" name="Reps" placeholder="42" value={reps} onValueUpdate={setReps} /> | ||
<div className="flex flex-row justify-evenly items-center mt-4" > | ||
<span className="text-sm"> | ||
<GhostButton type="button" onClick={handleClose}>Cancel</GhostButton> | ||
</span> | ||
<span className="text-xl"> | ||
<SolidButton type="submit" enabled={buttonEnabled}>Save</SolidButton> | ||
</span> | ||
</div> | ||
</Form> | ||
</ClientModal> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
type NumericInputProps = { | ||
htmlFor: string; | ||
type: string; | ||
step?: string; | ||
id: string; | ||
name: string; | ||
label: string; | ||
value?: number; | ||
placeholder: string; | ||
onValueUpdate?: (value: number) => void; | ||
required?: boolean; | ||
className?: string; | ||
} | ||
|
||
export default function NumericInput({htmlFor, step, id, name, label, value, placeholder, onValueUpdate, required = false}: NumericInputProps) { | ||
const onChange = (e: React.ChangeEvent<HTMLInputElement>) => { | ||
const value = parseFloat(e.target.value); | ||
onValueUpdate && onValueUpdate(value); | ||
} | ||
return ( | ||
<div className='flex flex-col mb-3'> | ||
<label htmlFor={htmlFor} className='mb-1 text-gray-700 dark:text-gray-100'>{label}</label> | ||
<input | ||
type='number' | ||
step={step} | ||
id={id} | ||
name={name} | ||
value={value} | ||
placeholder={placeholder} | ||
className='dark:text-gray-900 rounded-md border border-gray-300' | ||
required={required} | ||
onChange={onChange} | ||
/> | ||
</div> | ||
); | ||
} |