-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
feat: ํ๋ก์ ํธ ์ ๋ก๋ ๊ธฐ๋ฅ ๊ตฌํ
- Loading branch information
Showing
12 changed files
with
336 additions
and
126 deletions.
There are no files selected for viewing
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,17 @@ | ||
import axios from 'axios'; | ||
import { url } from '.'; | ||
import { getAuthAxios } from './authAxios'; | ||
import { IToken } from '@utils/state'; | ||
import { IProjectDetail, UploadData } from '@@types/request'; | ||
|
||
// export function postGalleryData(data: IProjectDetail, token: IToken) { | ||
// const authAxios = getAuthAxios(token); | ||
// return authAxios.post(`/api/admin/postProject`, { | ||
// data, | ||
// }); | ||
// } | ||
|
||
export async function postGalleryData(data: FormData) { | ||
const result = await axios.post(`${process.env.NEXT_PUBLIC_API_KEY}/api/project`, data); | ||
return result; | ||
} |
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
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,144 @@ | ||
import { IProjectDetail, UploadData } from '@@types/request'; | ||
import React, { useState } from 'react'; | ||
import { useRecoilValue } from 'recoil'; | ||
import { postGalleryData } from 'src/apis/admin'; | ||
import { token } from '@utils/state'; | ||
import useInput from 'src/hooks/useInput'; | ||
import styled from 'styled-components'; | ||
|
||
const PostAdmin = () => { | ||
// Input ์ํ ๊ด๋ฆฌ | ||
const [title, onChangeTitle] = useInput(''); | ||
const [subTitle, onChangeSubTitle] = useInput(''); | ||
const [devStack, onChangeDevStack] = useInput(''); | ||
const [version, onChangeVersion] = useInput(''); | ||
const [teamName, onChangeTeamName] = useInput(''); | ||
const [pm, onChangePm] = useInput(''); | ||
const [de, onChangeDe] = useInput(''); | ||
const [fe, onChangeFe] = useInput(''); | ||
const [be, onChangeBe] = useInput(''); | ||
const [start, onChangeStart] = useInput(''); | ||
const [end, onChangeEnd] = useInput(''); | ||
const [description, onChangeDescription] = useInput(''); | ||
const [webLink, onChangeWebLink] = useInput(''); | ||
const [category, onChangeCategory] = useInput(''); | ||
const [thumbnail, setThumbnail] = useState<File | null>(null); | ||
const [images, setImages] = useState<File[]>([]); | ||
const a: string = 'aaa'; | ||
// ํ์ผ ์ ๋ก๋ ํธ๋ค๋ฌ | ||
const handleThumbnailChange = (e: React.ChangeEvent<HTMLInputElement>) => { | ||
if (e.target.files && e.target.files[0]) { | ||
setThumbnail(e.target.files[0]); | ||
} | ||
}; | ||
|
||
const handleImagesChange = (e: React.ChangeEvent<HTMLInputElement>) => { | ||
if (e.target.files) { | ||
// e.target.files๊ฐ null์ด ์๋๋ฉด Array.from()์ผ๋ก ํ์ผ์ ๋ฐฐ์ด๋ก ๋ณํํ์ฌ ์ถ๊ฐ | ||
setImages((prevImages) => [ | ||
...prevImages, | ||
...Array.from(e.target.files as FileList), // FileList๋ก ๋ช ์์ ํ์ ์บ์คํ | ||
]); | ||
} | ||
}; | ||
|
||
// ์ ์ถ ํธ๋ค๋ฌ | ||
const handleSubmit = async () => { | ||
if (!thumbnail || images.length === 0) { | ||
alert('์ธ๋ค์ผ๊ณผ ์ด๋ฏธ์ง๋ฅผ ๋ชจ๋ ์ ๋ก๋ํด์ฃผ์ธ์.'); | ||
return; | ||
} | ||
|
||
const formData = new FormData(); | ||
|
||
formData.append('title', title); | ||
formData.append('subtitle', subTitle); | ||
formData.append('dev_stack', devStack); | ||
formData.append('version', version); | ||
formData.append('team_name', teamName); | ||
formData.append('start_date', start); | ||
formData.append('end_date', end); | ||
formData.append('description', description); | ||
formData.append('category', category); | ||
formData.append('login_email', 'adsf'); // ๋ก๊ทธ์ธ ์ด๋ฉ์ผ์ ์์ ๋ฐ์ดํฐ | ||
formData.append( | ||
'team_member', | ||
JSON.stringify({ | ||
pm: pm.split(','), | ||
design: de.split(','), | ||
frontend: fe.split(','), | ||
backend: be.split(','), | ||
}), | ||
); | ||
|
||
formData.append( | ||
'link', | ||
JSON.stringify({ | ||
github: 'fadsf', | ||
youtube: 'ffasd', | ||
web: webLink, | ||
}), | ||
); | ||
|
||
// ์ธ๋ค์ผ ํ์ผ ์ถ๊ฐ | ||
formData.append('thumbnail', thumbnail); | ||
|
||
// ์ด๋ฏธ์ง ๋ฐฐ์ด ์ถ๊ฐ | ||
images.forEach((image) => { | ||
formData.append('images', image); | ||
}); | ||
|
||
try { | ||
const result = await postGalleryData(formData); | ||
console.log(result); | ||
alert('์ ๋ก๋ ์ฑ๊ณต'); | ||
} catch (error) { | ||
console.error(error); | ||
alert('์ ๋ก๋ ์คํจ'); | ||
} | ||
}; | ||
|
||
return ( | ||
<Wrapper> | ||
<h1>ํ๋ก์ ํธ ์ ๋ก๋</h1> | ||
<input type="text" value={title} onChange={onChangeTitle} placeholder="์ ๋ชฉ" /> | ||
<input type="text" value={subTitle} onChange={onChangeSubTitle} placeholder="๋ถ์ ๋ชฉ" /> | ||
<input type="text" value={devStack} onChange={onChangeDevStack} placeholder="๊ฐ๋ฐ ์คํ" /> | ||
<input type="text" value={version} onChange={onChangeVersion} placeholder="๋ฒ์ " /> | ||
<input type="text" value={teamName} onChange={onChangeTeamName} placeholder="ํ ์ด๋ฆ" /> | ||
<input type="text" value={pm} onChange={onChangePm} placeholder="PM" /> | ||
<input type="text" value={de} onChange={onChangeDe} placeholder="๋์์ธ" /> | ||
<input type="text" value={fe} onChange={onChangeFe} placeholder="ํ๋ก ํธ์๋" /> | ||
<input type="text" value={be} onChange={onChangeBe} placeholder="๋ฐฑ์๋" /> | ||
<input type="string" value={start} onChange={onChangeStart} placeholder="์์ ๋ ์ง" /> | ||
<input type="string" value={end} onChange={onChangeEnd} placeholder="์ข ๋ฃ ๋ ์ง" /> | ||
<input type="string" onChange={onChangeDescription} placeholder="์ค๋ช "></input> | ||
<input type="url" value={webLink} onChange={onChangeWebLink} placeholder="์น ๋งํฌ" /> | ||
<input type="text" value={category} onChange={onChangeCategory} placeholder="์นดํ ๊ณ ๋ฆฌ" /> | ||
|
||
<Title>ํ๋ก์ ํธ ์ธ๋ค์ผ ์ด๋ฏธ์ง</Title> | ||
<input type="file" accept="image/*" onChange={handleThumbnailChange} /> | ||
|
||
<Title>ํ๋ก์ ํธ ์ด๋ฏธ์ง</Title> | ||
<input type="file" accept="image/*" multiple onChange={handleImagesChange} /> | ||
|
||
<button onClick={handleSubmit}>์ ๋ก๋ํ๊ธฐ</button> | ||
</Wrapper> | ||
); | ||
}; | ||
|
||
export default PostAdmin; | ||
|
||
const Wrapper = styled.div` | ||
width: 100%; | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: center; | ||
align-items: center; | ||
gap: 10px; | ||
`; | ||
|
||
const Title = styled.div` | ||
font-size: 2rem; | ||
font-weight: bold; | ||
`; |
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
Oops, something went wrong.