Skip to content

Commit

Permalink
endret møtevarighet til select
Browse files Browse the repository at this point in the history
  • Loading branch information
johatr committed Sep 11, 2023
1 parent 84bf52e commit f10bd4e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
28 changes: 19 additions & 9 deletions src/moduler/aktivitet/aktivitet-forms/mote/MoteAktivitetForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ const schema = z.object({
invalid_type_error: 'Ikke en gyldig dato',
}),
klokkeslett: z.string().min(1, 'Du må fylle ut klokkeslett'),

varighet: z.string().min(1, 'Du må fylle ut varighet'),
varighet: z.string().min(1, 'Du må velge varighet'),
kanal: z.nativeEnum(Kanal, {
errorMap: (issue) => {
switch (issue.code) {
Expand Down Expand Up @@ -128,13 +127,24 @@ const MoteAktivitetForm = (props: Props) => {
step="300"
error={errors.klokkeslett && errors.klokkeslett.message}
/>
<TextField
label="Varighet (obligatorisk)"
{...register('varighet')}
type={'time' as any}
step="900"
error={errors.varighet && errors.varighet.message}
/>
<Select label="Varighet (obligatorisk)" {...register('varighet')} error={errors.varighet && errors.varighet.message} >
<option value={30}>30 minutter</option>
<option value={45}>45 minutter</option>
<option value={60}>1 time</option>
<option value={90}>1 time, 30 minutter</option>
<option value={120}>2 timer</option>
<option value={150}>2 timer, 30 minutter</option>
<option value={180}>3 timer</option>
<option value={210}>3 timer, 30 minutter</option>
<option value={240}>4 timer</option>
<option value={270}>4 timer, 30 minutter</option>
<option value={300}>5 timer</option>
<option value={330}>5 timer, 30 minutter</option>
<option value={360}>6 timer</option>
<option value={390}>6 timer, 30 minutter</option>
<option value={420}>7 timer</option>
<option value={450}>7 timer, 30 minutter</option>
</Select>
<Select label="Møteform (obligatorisk)" {...register('kanal')} error={errors.kanal && errors.kanal.message}>
<option value="">Velg møteform</option>
<option value={Kanal.OPPMOTE}>Oppmøte</option>
Expand Down
13 changes: 10 additions & 3 deletions src/moduler/aktivitet/aktivitet-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,7 @@ export function beregnFraTil(data: MoteTid): FraTil {
if (dato && klokkeslett && validKlokkeslett(klokkeslett) && varighet !== undefined && varighet !== null) {
const { hour, minute } = toHourAndMinutes(klokkeslett);
const fraDato = setMinutes(setHours(startOfDay(toDate(dato)), hour), minute);
const { hour: varighetHours, minute: varighetMinutes } = toHourAndMinutes(varighet);
const tilDato = addMinutes(fraDato, varighetHours * 60 + varighetMinutes);
const tilDato = addMinutes(fraDato, varighet);
return {
fraDato: fraDato.toISOString(),
tilDato: tilDato.toISOString(),
Expand All @@ -176,7 +175,15 @@ export function formatterVarighet(varighet?: string | number): string | undefine
if (!varighet) return undefined;
if (typeof varighet === 'number' || !isNaN(parseInt(varighet))) {
const { hour, minute } = toHourAndMinutes(varighet);
return `${prefixMed0(hour.toString())}:${prefixMed0(minute.toString())}`;
if (hour > 0) {
if (minute > 0) {
return `${hour.toString()} ${hour === 1 ? 'time' : 'timer'}, ${prefixMed0(minute.toString())} minutter`;
} else {
return `${hour.toString()} ${hour === 1 ? 'time' : 'timer'}`;
}
} else {
return `${prefixMed0(minute.toString())} minutter`;
}
} else {
// Assuming this is correctly formatted "HH:ss"
return varighet;
Expand Down

0 comments on commit f10bd4e

Please sign in to comment.