Skip to content

Commit

Permalink
🔥 Fjerner Object.assign
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasrognes committed Oct 6, 2023
1 parent 261f462 commit 945231e
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 15 deletions.
4 changes: 2 additions & 2 deletions packages/aap-felles-react/src/FileInput/FileInput.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Meta, StoryFn } from '@storybook/react';

import { FileInput, FileInputProps, Attachment } from './FileInput';
import { FileInput, FileInputProps, Vedleggg } from './FileInput';
import React, { useState } from 'react';

// More on default export: https://storybook.js.org/docs/react/writing-stories/introduction#default-export
Expand All @@ -10,7 +10,7 @@ export default {
} as Meta;

export const Primary: StoryFn<FileInputProps> = (args) => {
const [files, setFiles] = useState<Attachment[]>([]);
const [files, setFiles] = useState<Vedleggg[]>([]);
return (
<FileInput
{...args}
Expand Down
4 changes: 2 additions & 2 deletions packages/aap-felles-react/src/FileInput/FileInput.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { enableFetchMocks } from 'jest-fetch-mock';
import { v4 as uuidV4 } from 'uuid';
import React, { ReactElement, useState } from 'react';
import { FileInput, FileInputProps, Attachment } from './FileInput';
import { FileInput, FileInputProps, Vedleggg } from './FileInput';
import { fireEvent, render, screen, waitFor } from '@testing-library/react';

import userEvent from '@testing-library/user-event';
Expand Down Expand Up @@ -211,7 +211,7 @@ export function FileInputWithState(
'onChange' | 'uploadUrl' | 'heading' | 'id' | 'deleteUrl' | 'onUpload' | 'onDelete' | 'files'
>
): ReactElement {
const [files, setFiles] = useState<Attachment[]>([]);
const [files, setFiles] = useState<Vedleggg[]>([]);

return (
<FileInput
Expand Down
20 changes: 13 additions & 7 deletions packages/aap-felles-react/src/FileInput/FileInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,20 @@ import { FilePanelSuccess } from './FilePanelSuccess';
export interface FileInputProps extends InputHTMLAttributes<HTMLInputElement> {
heading: string;
id: string;
onUpload: (attachments: Attachment[]) => void;
onDelete: (attachment: Attachment) => void;
onUpload: (attachments: Vedleggg[]) => void;
onDelete: (attachment: Vedleggg) => void;
deleteUrl: string;
uploadUrl: string;
files: Attachment[];
files: Vedleggg[];
ingress?: string;
}

export interface Attachment extends File {
export interface Vedleggg {
id: string;
errorMessage?: string;
size: number;
name: string;
type: string;
}

const MAX_TOTAL_FILE_SIZE = 52428800; // 50mb
Expand All @@ -43,12 +46,15 @@ export const FileInput = (props: FileInputProps) => {

async function validateAndSetFiles(filelist: FileList) {
setIsUploading(true);
const uploadedFiles: Attachment[] = await Promise.all(
const uploadedFiles: Vedleggg[] = await Promise.all(
Array.from(filelist).map(async (file) => {
const internalErrorMessage = internalValidate(file);
let uploadResult = {
let uploadResult: Vedleggg = {
id: uuidV4(),
errorMessage: '',
type: file.type,
size: file.size,
name: file.name,
};

if (!internalErrorMessage) {
Expand All @@ -70,7 +76,7 @@ export const FileInput = (props: FileInputProps) => {
uploadResult.errorMessage = internalErrorMessage;
}

return Object.assign(file, uploadResult);
return uploadResult;
})
);

Expand Down
4 changes: 2 additions & 2 deletions packages/aap-felles-react/src/FileInput/FilePanelError.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { BodyShort, Label, Panel } from '@navikt/ds-react';
import { ArrowUndoIcon, FileTextIcon } from '@navikt/aksel-icons';
import React from 'react';
import { Attachment } from './FileInput';
import { Vedleggg } from './FileInput';

interface Props {
file: Attachment;
file: Vedleggg;
deleteUrl: string;
onDelete: () => void;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/aap-felles-react/src/FileInput/FilePanelSuccess.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { CheckmarkIcon, XMarkIcon } from '@navikt/aksel-icons';
import { BodyShort, Detail, Link, Panel } from '@navikt/ds-react';
import React from 'react';
import { Attachment } from './FileInput';
import { Vedleggg } from './FileInput';

interface Props {
file: Attachment;
file: Vedleggg;
onDelete: () => void;
}

Expand Down

0 comments on commit 945231e

Please sign in to comment.