Skip to content

Commit

Permalink
move ui to core
Browse files Browse the repository at this point in the history
  • Loading branch information
ramiAbdou committed Jul 26, 2024
1 parent c0fbeca commit d0471ac
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,13 @@ import {
} from '@remix-run/node';
import { Form as RemixForm, useActionData } from '@remix-run/react';

import { importScholarshipRecipients } from '@oyster/core/scholarships';
import { ImportRecipientsInput } from '@oyster/core/scholarships.types';
import {
Button,
FileUploader,
Form,
getErrors,
Modal,
validateForm,
} from '@oyster/ui';
ImportRecipientsInput,
importScholarshipRecipients,
} from '@oyster/core/scholarships';
import { Button, Form, getErrors, Modal, validateForm } from '@oyster/ui';

import { ScholarshipFileField } from '@/modules/scholarship/scholarship.ui';
import { Route } from '@/shared/constants';
import {
commitSession,
Expand Down Expand Up @@ -72,45 +68,22 @@ export async function action({ request }: ActionFunctionArgs) {
}

export default function ImportScholarshipsPage() {
const { error, errors } = getErrors(useActionData<typeof action>());

return (
<Modal onCloseTo={Route['/students']}>
<Modal.Header>
<Modal.Title>Import Scholarship Recipients</Modal.Title>
<Modal.CloseButton />
</Modal.Header>

<ImportScholarshipsForm />
<RemixForm className="form" method="post" encType="multipart/form-data">
<ScholarshipFileField error={errors.file} />
<Form.ErrorMessage>{error}</Form.ErrorMessage>
<Button.Group>
<Button.Submit>Import</Button.Submit>
</Button.Group>
</RemixForm>
</Modal>
);
}

const keys = ImportRecipientsInput.keyof().enum;

function ImportScholarshipsForm() {
const { error, errors } = getErrors(useActionData<typeof action>());

return (
<RemixForm className="form" method="post" encType="multipart/form-data">
<Form.Field
description="Please upload a .csv file."
error={errors.file}
label="File"
labelFor={keys.file}
required
>
<FileUploader
accept={['text/csv']}
id={keys.file}
name={keys.file}
required
/>
</Form.Field>

<Form.ErrorMessage>{error}</Form.ErrorMessage>

<Button.Group>
<Button.Submit>Import</Button.Submit>
</Button.Group>
</RemixForm>
);
}
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"./resume-books.types": "./src/modules/resume-book/resume-book.types.ts",
"./resume-books.ui": "./src/modules/resume-book/resume-book.ui.tsx",
"./scholarships": "./src/modules/scholarship/scholarship.core.ts",
"./scholarships.types": "./src/modules/scholarship/scholarship.types.ts",
"./scholarships.ui": "./src/modules/scholarship/scholarship.ui.tsx",
"./slack.server": "./src/modules/slack/index.server.ts"
},
"scripts": {
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/modules/scholarship/scholarship.core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import {
import { ColorStackError } from '@/shared/errors';
import { parseCsv } from '@/shared/utils/csv.utils';

export { ImportRecipientsInput } from '@/modules/scholarship/scholarship.types';

const ScholarshipRecipientRow = z.object({
Amount: ScholarshipRecipient.shape.amount,

Expand Down
26 changes: 26 additions & 0 deletions packages/core/src/modules/scholarship/scholarship.ui.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { type FieldProps, FileUploader, Form } from '@oyster/ui';

import { ImportRecipientsInput } from '@/modules/scholarship/scholarship.types';

const importKeys = ImportRecipientsInput.keyof().enum;

export function ScholarshipFileField({
error,
}: Pick<FieldProps<string>, 'error'>) {
return (
<Form.Field
description="Please upload a .csv file."
error={error}
label="File"
labelFor={importKeys.file}
required
>
<FileUploader
accept={['text/csv']}
id={importKeys.file}
name={importKeys.file}
required
/>
</Form.Field>
);
}

0 comments on commit d0471ac

Please sign in to comment.