-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโll occasionally send you account related emails.
Already on GitHub? Sign in to your account
grade upload/#9 #41
Merged
Merged
grade upload/#9 #41
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
2dfa861
feat: implement upload-file component
yougyung 75c9882
chore: commit for merge
yougyung c3bc1ba
feat: implement file-upload manual
yougyung 8c37597
feat: implement useFile hook
yougyung d0548ce
feat: add file-upload stories
yougyung 1930ff7
chore: fix example variable
yougyung 7ea12c6
refactor: api request in server component
yougyung 4dc8853
chore: add todo comment
yougyung edad423
chore: commit for merge
yougyung 8006519
fix: upload grade structure
yougyung 39fe4d7
refactor: use form component
yougyung 421c5d0
feat: add fileupload test
yougyung c87c9fc
fix: remove fileinput drag&drop handler
yougyung b38ff02
rename: change to usePdfFile, uploadTakenLecture
yougyung b3dac84
style: add option truncate
yougyung a7486e6
chore: remove unnecessary code
yougyung f05c75e
fix: change variable name
yougyung c54c917
fix: change target grade-upload test
yougyung File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
export default function Manual() { | ||
return ( | ||
<div className="flex justify-center"> | ||
<div className="flex flex-col gap-6"> | ||
<h1 className="text-center text-3xl font-bold p-4 border-b-2 border-gray-100 md:text-4xl"> | ||
ํ ๋ฒ์ ์ฑ์ ํ ์ ๋ ฅ์ผ๋ก | ||
<br /> ๋ง์ถคํ ๊ฒฐ๊ณผ๋ฅผ ํ์ธํ์ธ์ ! | ||
</h1> | ||
<div className="text-base flex flex-col gap-2 md:text-lg"> | ||
<div> | ||
1. | ||
<a | ||
target="_blank" | ||
className="pl-1 text-primary hover:text-dark-hover" | ||
href="https://msi.mju.ac.kr/servlet/security/MySecurityStart" | ||
> | ||
MyiWeb MSI | ||
</a> | ||
์ ์ ์ ํ ๋ก๊ทธ์ธ(PCํ๊ฒฝ ๊ถ์ฅ) | ||
</div> | ||
<div>2. ์ข์ธก ์ฑ์ /์กธ์ ๋ฉ๋ด โ ์ฑ์ ํ(์๋ด์ฉ,B4)ํด๋ฆญ</div> | ||
<div>3. ์ฐ์ธก ์๋จ ์กฐํ๋ฒํผ ํด๋ฆญ โ ํ๋ฆฐํธ ์์ด์ฝ ํด๋ฆญ</div> | ||
<div>4. ์ธ์ ์ ๋ณด์ ๋์(PDF๋ก ์ ์ฅ) ์ค์ โ ํ๋จ ์ ์ฅ ๋ฒํผ ํด๋ฆญ </div> | ||
<div>5. ์ ์ฅํ ํ์ผ ์ ๋ก๋ </div> | ||
<div className="text-xs md:text-sm text-primary"> | ||
โข ํ์ ๊ฐ์ ํ ํ๋ฒ๊ณผ ์ผ์นํ๋ ํ๋ฒ์ ์ฑ์ ํ๋ฅผ ์ ๋ ฅํด์ผ ํฉ๋๋ค. | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import ContentContainer from '../../ui/view/atom/content-container'; | ||
import Manual from './components/manual'; | ||
import UploadTakenLecture from '../../ui/lecture/upload-taken-lecture/upload-taken-lecture'; | ||
|
||
export default function GradeUploadPage() { | ||
return ( | ||
<ContentContainer className="flex flex-col justify-center gap-8 min-h-[70vh]"> | ||
<Manual /> | ||
<UploadTakenLecture /> | ||
</ContentContainer> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import UploadPdf from '@/app/ui/view/molecule/upload-pdf/upload-pdf'; | ||
import { render, screen } from '@testing-library/react'; | ||
import { userEvent } from '@testing-library/user-event'; | ||
|
||
describe('์ฑ์ ์ ๋ก๋', () => { | ||
it('ํ์ผ์ด ์ ๋ก๋ ๋ ๋, pdf file์ ์ ๋ก๋ ํ๋ฉด file๋ช ์ด ๋ ธ์ถ๋๋ค.', async () => { | ||
render(<UploadPdf />); | ||
|
||
const targetFile = new File(['grade'], 'grade.pdf', { | ||
type: 'text/plain', | ||
}); | ||
|
||
const uploadBox = await screen.findByTestId('upload-box'); | ||
await userEvent.upload(uploadBox, targetFile); | ||
|
||
expect(screen.getByText(targetFile.name)).toBeInTheDocument(); | ||
}); | ||
|
||
it('ํ์ผ์ด ์ ๋ก๋ ๋ ๋, pdf๊ฐ ์๋ file์ ์ ๋ก๋ ํ๋ฉด ๋ณํ๊ฐ ๋ฐ์ํ์ง์๋๋ค.', async () => { | ||
render(<UploadPdf />); | ||
|
||
const targetFile = new File(['grade'], 'grade.png', { | ||
type: 'text/plain', | ||
}); | ||
|
||
const uploadBox = await screen.findByTestId('upload-box'); | ||
await userEvent.upload(uploadBox, targetFile); | ||
expect(screen.queryByText('๋ง์ฐ์ค๋ก ๋๋๊ทธ ํ๊ฑฐ๋ ์์ด์ฝ์ ๋๋ฌ ์ถ๊ฐํด์ฃผ์ธ์.')).toBeInTheDocument(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
'use server'; | ||
import { FormState } from '@/app/ui/view/molecule/form/form-root'; | ||
import { API_PATH } from '../api-path'; | ||
|
||
export const registerUserGrade = async (prevState: FormState, formData: FormData) => { | ||
const parsingText = await parsePDFtoText(formData); | ||
|
||
const res = await fetch(API_PATH.registerUserGrade, { | ||
method: 'POST', | ||
body: JSON.stringify({ parsingText }), | ||
}); | ||
|
||
if (!res.ok) { | ||
return { | ||
errors: {}, | ||
message: 'fail upload grade', | ||
}; | ||
} | ||
|
||
return { | ||
errors: {}, | ||
message: '', | ||
}; | ||
}; | ||
|
||
export const parsePDFtoText = async (formData: FormData) => { | ||
const res = await fetch(API_PATH.parsePDFtoText, { method: 'POST', body: formData }); | ||
if (!res.ok) { | ||
return { | ||
errors: {}, | ||
message: 'fail parsing to text', | ||
}; | ||
} | ||
return await res.json(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { useState } from 'react'; | ||
import { z } from 'zod'; | ||
|
||
export type FileType = File | null; | ||
|
||
export default function usePdfFile() { | ||
const [file, setFile] = useState<FileType>(null); | ||
|
||
const changeFile = (file: File) => { | ||
if (!validate.parse(file.name)) return; | ||
setFile(file); | ||
}; | ||
|
||
const validate = z.string().refine((value) => value.endsWith('.pdf'), { | ||
message: 'File must be a PDF', | ||
}); | ||
|
||
return { file, changeFile }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
app/ui/lecture/upload-taken-lecture/upload-taken-lecture.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
'use client'; | ||
|
||
import { registerUserGrade } from '@/app/business/lecture/taken-lecture.command'; | ||
import UploadPdf from '@/app/ui/view/molecule/upload-pdf/upload-pdf'; | ||
import Form from '../../view/molecule/form'; | ||
|
||
function UploadTakenLecture() { | ||
return ( | ||
<Form action={registerUserGrade} id="์ฑ์ ์ ๋ก๋"> | ||
<UploadPdf /> | ||
<Form.SubmitButton label="๊ฒฐ๊ณผ ๋ณด๋ฌ๊ฐ๊ธฐ" position="center" size="md" /> | ||
</Form> | ||
); | ||
} | ||
|
||
export default UploadTakenLecture; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
import UploadPdf from './upload-pdf'; | ||
|
||
const meta = { | ||
title: 'ui/view/molecule/UploadFile', | ||
component: UploadPdf, | ||
} satisfies Meta<typeof UploadPdf>; | ||
|
||
export default meta; | ||
|
||
export const Default: StoryObj<typeof meta> = { | ||
render: () => <UploadPdf />, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
'use client'; | ||
import Image from 'next/image'; | ||
import uploadBox from '@/public/assets/upload-box.svg'; | ||
import checkedBox from '@/public/assets/checked-box.svg'; | ||
import usePdfFile from '@/app/hooks/usePdfFile'; | ||
import { ChangeEvent } from 'react'; | ||
|
||
function UploadPdf() { | ||
const { file, changeFile } = usePdfFile(); | ||
|
||
const handleChangeFileInput = (event: ChangeEvent<HTMLInputElement>) => { | ||
const { files } = event.target; | ||
if (files) changeFile(files[0]); | ||
}; | ||
|
||
return ( | ||
<div className="flex flex-col items-center gap-4"> | ||
<div | ||
role="button" | ||
className="relative p-2 m-auto w-96 flex flex-col justify-center items-center gap-2 border-dashed border-2 rounded-sm rounded-bl-xl border-light-blue-6 bg-light-blue-1 text-light-blue-6 max-lg:w-80" | ||
> | ||
<Image src={file ? checkedBox : uploadBox} width={40} height={28} className="mx-auto" alt="upload-button" /> | ||
<span className="text-center break-keep whitespace-pre-line max-w-48 truncate"> | ||
{file ? file.name : '๋ง์ฐ์ค๋ก ๋๋๊ทธ ํ๊ฑฐ๋ ์์ด์ฝ์ ๋๋ฌ ์ถ๊ฐํด์ฃผ์ธ์.'} | ||
</span> | ||
<input | ||
onChange={handleChangeFileInput} | ||
type="file" | ||
className="absolute bg-black opacity-0 w-96 max-lg:w-80 h-full" | ||
name="file" | ||
accept=".pdf" | ||
data-testid="upload-box" | ||
required | ||
/> | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
export default UploadPdf; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getByText๋ queryByText ์ฌ์ฉํ๋ ๊ธฐ์ค์ ์ฌ์ญค๋ด๋ ๋ ๊น์!?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
๊ฐ๋ฐ๊ณผ์ ์์ ๋ก์ง์ ์ํด ๋ฉ์๋๋ฅผ ๋ค๋ฅด๊ฒ ๊ฐ์ ธ๊ฐ๋๋ฐ, ๋ณ๊ฒฝ์ด ๋ฐ์ํ๋ฉด์ ํ์ฌ๋ ์ด๋ค ๋ฉ์๋๋ฅผ ์ฌ์ฉํด๋ ์ ์ฉ์ด ๋๋ ์ํฉ์ ๋๋ค!