-
Notifications
You must be signed in to change notification settings - Fork 4
✨feat: 공고 편집 페이지 추가 및 반응형 작업 #82 #89
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
Merged
gummmmmy0v0
merged 3 commits into
codeit-FE18-part3:develop
from
gummmmmy0v0:feature/#82-1
Oct 18, 2025
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 contains hidden or 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,178 @@ | ||
| import { Button, DateInput, Input, Modal, TimeInput } from '@/components/ui'; | ||
| import useAuth from '@/hooks/useAuth'; | ||
| import axiosInstance from '@/lib/axios'; | ||
| import { useRouter } from 'next/router'; | ||
| import { useEffect, useState } from 'react'; | ||
|
|
||
| interface NoticePayload { | ||
| hourlyPay: number; | ||
| startsAt: string; | ||
| workhour: number; | ||
| description: string; | ||
| } | ||
|
|
||
| const EmployerNoticeEditPage = () => { | ||
| const router = useRouter(); | ||
| const { user } = useAuth(); | ||
| const { noticeId } = router.query; | ||
|
|
||
| const [wage, setWage] = useState(''); | ||
| const [date, setDate] = useState<Date | null>(null); | ||
| const [time, setTime] = useState<Date | null>(null); | ||
| const [workhour, setWorkhour] = useState<number>(); | ||
| const [description, setDescription] = useState(''); | ||
|
|
||
| const [loading, setLoading] = useState(true); | ||
| const [modalOpen, setModalOpen] = useState(false); | ||
|
|
||
| useEffect(() => { | ||
| if (!user) return; | ||
| if (!user.shop) { | ||
| alert('접근 권한이 없습니다.'); | ||
| router.replace('/'); | ||
| return; | ||
| } | ||
|
|
||
| const fetchNotice = async () => { | ||
| try { | ||
| const response = await axiosInstance.get( | ||
| `/shops/${user.shop?.item.id}/notices/${noticeId}` | ||
| ); | ||
| const notice = response.data.item; | ||
|
|
||
| setWage(notice.hourlyPay.toString()); | ||
| setWorkhour(notice.workhour); | ||
| setDescription(notice.description); | ||
|
|
||
| const startDate = new Date(notice.startsAt); | ||
| setDate(startDate); | ||
| setTime(startDate); | ||
| } catch { | ||
| alert('공고 정보를 불러오는 중 오류가 발생했습니다.'); | ||
| router.back(); | ||
| } finally { | ||
| setLoading(false); | ||
| } | ||
| }; | ||
|
|
||
| if (noticeId) fetchNotice(); | ||
| }, [noticeId, user, router]); | ||
|
|
||
| const handleSubmit = async (e: React.FormEvent<HTMLFormElement>) => { | ||
| e.preventDefault(); | ||
|
|
||
| if (!date || !time || !wage || !workhour || !description) return; | ||
| if (!user?.shop || !noticeId) return; | ||
|
|
||
| const combinedDateTime = new Date(date); | ||
| combinedDateTime.setHours(time.getHours(), time.getMinutes(), 0, 0); | ||
|
|
||
| const payload: NoticePayload = { | ||
| hourlyPay: Number(wage), | ||
| startsAt: combinedDateTime.toISOString(), | ||
| workhour, | ||
| description, | ||
| }; | ||
|
|
||
| try { | ||
| await axiosInstance.put(`/shops/${user.shop.item.id}/notices/${noticeId}`, payload); | ||
| setModalOpen(true); | ||
| } catch (error) { | ||
| alert(error instanceof Error ? error.message : '공고 수정 중 오류 발생'); | ||
| } | ||
| }; | ||
|
|
||
| const handleModalClose = () => { | ||
| setModalOpen(false); | ||
| if (user?.shop) { | ||
| router.push(`/employer/shops/${user.shop.item.id}/notices/${noticeId}`); | ||
| } | ||
| }; | ||
|
|
||
| if (loading) return; | ||
| if (!user?.shop) return null; | ||
|
|
||
| return ( | ||
| <div className='p-4'> | ||
| <p className='mb-4 text-3xl font-bold'>공고 편집</p> | ||
|
|
||
| <form onSubmit={handleSubmit} className='flex w-full flex-col gap-4'> | ||
| <div className='grid grid-cols-1 gap-4 tablet:grid-cols-2 tablet:gap-6'> | ||
| <Input | ||
| id='wage' | ||
| label='시급' | ||
| requiredMark | ||
| placeholder='12,500' | ||
| inputMode='numeric' | ||
| suffix='원' | ||
| value={wage} | ||
| onChange={e => setWage(e.currentTarget.value.replace(/\D+/g, ''))} | ||
| /> | ||
|
|
||
| <Input | ||
| id='workhour' | ||
| label='업무 시간' | ||
| requiredMark | ||
| placeholder='4' | ||
| inputMode='numeric' | ||
| suffix='시간' | ||
| value={workhour?.toString() ?? ''} | ||
| onChange={e => setWorkhour(Number(e.currentTarget.value))} | ||
| /> | ||
|
|
||
| <DateInput | ||
| label='시작 날짜' | ||
| requiredMark | ||
| value={date ?? undefined} | ||
| onChange={selectedDate => | ||
| setDate(selectedDate instanceof Date ? selectedDate : new Date(selectedDate)) | ||
| } | ||
| /> | ||
|
|
||
| <TimeInput | ||
| label='시작 시간' | ||
| requiredMark | ||
| value={time ?? undefined} | ||
| onChange={(selectedTime: Date | null) => setTime(selectedTime)} | ||
| /> | ||
| </div> | ||
|
|
||
| <div className='flex flex-col gap-2'> | ||
| <label htmlFor='description' className='text-sm font-medium'> | ||
| 공고 설명 | ||
| </label> | ||
| <textarea | ||
| id='description' | ||
| name='description' | ||
| className='rounded-md border border-gray-300 p-2 focus:outline-none focus:ring-2 focus:ring-blue-400' | ||
| rows={4} | ||
| placeholder='공고에 대한 설명을 입력하세요.' | ||
| value={description} | ||
| onChange={e => setDescription(e.target.value)} | ||
| /> | ||
| </div> | ||
|
|
||
| <Button | ||
| type='submit' | ||
| variant='primary' | ||
| size='lg' | ||
| className='mt-5 w-full' | ||
| disabled={!wage || !date || !time || !workhour || !description} | ||
| > | ||
| 등록하기 | ||
| </Button> | ||
| </form> | ||
|
|
||
| <Modal | ||
| open={modalOpen} | ||
| onClose={handleModalClose} | ||
| title='편집 완료' | ||
| variant='success' | ||
| primaryText='확인' | ||
| onPrimary={handleModalClose} | ||
| /> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export default EmployerNoticeEditPage; | ||
This file contains hidden or 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 hidden or 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.
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.
Uh oh!
There was an error while loading. Please reload this page.