Skip to content

Commit

Permalink
♻️ Bruker fileinput fra felles lib
Browse files Browse the repository at this point in the history
Co-authored-by: Thomas Rognes <[email protected]>
Co-authored-by: Halvor Grizzly Bjørn <[email protected]>
Co-authored-by: Tor Idland <[email protected]>
  • Loading branch information
4 people authored Oct 18, 2023
2 parents 3e82bdf + 36c0d20 commit 5805cbc
Show file tree
Hide file tree
Showing 20 changed files with 564 additions and 844 deletions.
40 changes: 22 additions & 18 deletions components/FormErrorSummary/FormErrorSummary.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,33 @@
import React, { useRef } from 'react';
import { FieldErrors } from 'react-hook-form';
import { ErrorSummary } from '@navikt/ds-react';
import * as classes from 'components/FormErrorSummary/FormErrorSummary.module.css';
import { useFeatureToggleIntl } from 'lib/hooks/useFeatureToggleIntl';
import { flattenObject } from '@navikt/aap-felles-utils-client';

const FormErrorSummary = (props: { id: string; errors: FieldErrors }) => {
export interface Error {
path: string;
message?: string;
id: string;
}

interface Props {
id: string;
errors: Error[];
}

const FormErrorSummary = ({ id, errors }: Props) => {
const { formatMessage } = useFeatureToggleIntl();

const flatErrors = flattenObject(props?.errors);
const keyList = Object.keys(flatErrors).filter((key: string) => flatErrors[key] !== undefined);
const errorSummaryElement = useRef(null);

if (keyList?.length < 1) {
if (errors?.length < 1) {
return (
<ErrorSummary
ref={errorSummaryElement}
heading={formatMessage('errorSummary.title')}
role={'alert'}
aria-hidden={keyList?.length === 0}
className={keyList?.length === 0 ? classes?.visuallyHidden : ''}
{...props}
aria-hidden={errors?.length === 0}
className={errors?.length === 0 ? classes?.visuallyHidden : ''}
id={id}
>
{'hidden'}
</ErrorSummary>
Expand All @@ -33,16 +40,13 @@ const FormErrorSummary = (props: { id: string; errors: FieldErrors }) => {
ref={errorSummaryElement}
heading={formatMessage('errorSummary.title')}
role={'alert'}
aria-hidden={keyList?.length === 0}
className={keyList?.length === 0 ? classes?.visuallyHidden : ''}
{...props}
aria-hidden={errors?.length === 0}
className={errors?.length === 0 ? classes?.visuallyHidden : ''}
id={id}
>
{keyList.map((key) => (
<ErrorSummary.Item key={key} href={`#${key}`}>
{
// @ts-ignore
flatErrors[key]
}
{errors.map((error, index) => (
<ErrorSummary.Item key={index} href={`#${error.path}`}>
{error.message}
</ErrorSummary.Item>
))}
</ErrorSummary>
Expand Down
23 changes: 0 additions & 23 deletions components/Inputs/FileInput.module.css

This file was deleted.

124 changes: 0 additions & 124 deletions components/Inputs/FileInput.tsx

This file was deleted.

7 changes: 0 additions & 7 deletions components/Inputs/FileUpload.module.css

This file was deleted.

Loading

0 comments on commit 5805cbc

Please sign in to comment.