Skip to content
This repository has been archived by the owner on Apr 24, 2024. It is now read-only.

Autofill harvest year to current year #114

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions frontend/src/components/Form/SimpleFormInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ interface SimpleFormInputProps<T extends FieldValues> {
isArea?: boolean;
required?: boolean;
type?: HTMLInputTypeAttribute;
defaultValue?: string | number | readonly string[];
min?: number;
max?: number;
register?: UseFormRegister<T>;
Expand All @@ -23,6 +24,7 @@ export default function SimpleFormInput<T extends FieldValues>({
required = false,
isArea = false,
type = 'text',
defaultValue,
min,
max,
id,
Expand All @@ -31,6 +33,7 @@ export default function SimpleFormInput<T extends FieldValues>({
valueAsNumber = false,
errorTitle,
}: SimpleFormInputProps<T>) {

return (
<div>
<label htmlFor={id} className="mb-2 block text-sm font-medium text-white">
Expand All @@ -55,6 +58,7 @@ export default function SimpleFormInput<T extends FieldValues>({
min={min}
max={max}
id={id}
defaultValue={defaultValue}
className="block h-11 w-full rounded-lg border border-zinc-800 bg-primary-textfield p-2.5 text-sm text-white placeholder-neutral-700 focus:border-gray-600 focus:outline-none"
placeholder={placeHolder}
required={required}
Expand Down
5 changes: 4 additions & 1 deletion frontend/src/features/seeds/components/CreateSeedForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ interface CreateSeedFormProps {
const CreateSeedForm = ({ onCancel, onChange, onSubmit }: CreateSeedFormProps) => {
const quality: SelectOption[] = enumToSelectOptionArr(Quality);
const quantity: SelectOption[] = enumToSelectOptionArr(Quantity);

const currentYear = new Date().getFullYear();

const findAllPlants = useCreateSeedStore((state) => state.findAllPlants);
const plants = useCreateSeedStore((state) =>
Expand Down Expand Up @@ -56,7 +58,8 @@ const CreateSeedForm = ({ onCancel, onChange, onSubmit }: CreateSeedFormProps) =
<SimpleFormInput
type="number"
labelText="Bezugsjahr"
placeHolder="2023"
defaultValue={currentYear}
placeHolder={currentYear.toString()}
required={true}
id="harvest_year"
register={register}
Expand Down