Skip to content

Commit

Permalink
Legg til enkel støtte for redigering av dato
Browse files Browse the repository at this point in the history
Co-authored-by: Tonje Mjøvik Myran <[email protected]>
Co-authored-by: Eivind Havnelid Røyrvik <[email protected]>
Co-authored-by: Sindre Sægrov <[email protected]>
Co-authored-by: Mette Wendy Lindberg Gulbrandsen <[email protected]>
  • Loading branch information
5 people committed Oct 24, 2024
1 parent 44e008f commit e649878
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions app/components/opplysning/OpplysningDato.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
import { DatePicker, useDatepicker } from "@navikt/ds-react";
import { addYears, subYears } from "date-fns";
import { addYears, formatISO, subYears } from "date-fns";
import { useField } from "remix-validated-form";
import type { IOpplysningProps } from "~/components/opplysning/Opplysning";
import { formaterNorskDato } from "~/utils/dato.utils";
import styles from "./Opplysning.module.css";

export function OpplysningDato({ opplysning, readonly, label, className }: IOpplysningProps) {
export function OpplysningDato({
opplysning,
readonly,
label,
className,
onChange,
}: IOpplysningProps) {
const { error, getInputProps } = useField(opplysning.navn);

const { datepickerProps, inputProps } = useDatepicker({
defaultSelected: opplysning.verdi ? new Date(opplysning.verdi) : undefined,
toDate: addYears(new Date(), 100),
fromDate: subYears(new Date(), 100),
onDateChange: (date) => {
if (date) {
onChange(formatISO(date, { representation: "date" }));
}
},
});

return (
Expand Down

0 comments on commit e649878

Please sign in to comment.