-
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.
Merge pull request #156 from YIMSEBIN/Weekly
Feat: ํ ์คํธ์ฝ๋ ๊ตฌํ ๋ฐ POST ํ์ธ ๋ชจ๋ฌ์ฐฝ ๊ตฌํ
- Loading branch information
Showing
18 changed files
with
1,526 additions
and
795 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
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
66 changes: 66 additions & 0 deletions
66
src/features/contract/EmployeeContract/__test__/employeeContract.test.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,66 @@ | ||
import { fireEvent, screen } from '@testing-library/react'; | ||
import { server } from '@/mocks/server'; | ||
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'; | ||
import { renderWithProviders } from '@/__test__/test-utils'; | ||
import ContractSection from '../components/ContractSection'; | ||
import { useNavigate } from 'react-router-dom'; | ||
import ROUTE_PATH from '@/routes/path'; | ||
|
||
const mockNavigate = vi.fn(); | ||
vi.mock('react-router-dom', async () => { | ||
return { | ||
...(await vi.importActual('react-router-dom')), | ||
useNavigate: vi.fn(), | ||
}; | ||
}); | ||
|
||
describe('employeeContract', () => { | ||
beforeAll(() => { | ||
server.listen(); | ||
vi.mocked(useNavigate).mockImplementation(() => mockNavigate); | ||
}); | ||
afterEach(() => server.resetHandlers()); | ||
afterAll(() => server.close()); | ||
|
||
beforeEach(() => { | ||
vi.clearAllMocks(); | ||
}); | ||
|
||
const renderContract = () => { | ||
return renderWithProviders(<ContractSection />); | ||
}; | ||
|
||
it('๊ทผ๋ก๊ณ์ฝ์ ๋ฐ์ดํฐ ์ ๋ถ๋ ค์์ง', async () => { | ||
renderContract(); | ||
|
||
expect(screen.getByText('contract.WORKING_PLACE')).toBeInTheDocument(); | ||
expect(screen.getByText('contract.RESPONSIBILITIES')).toBeInTheDocument(); | ||
expect(screen.getByText('contract.WORKING_HOURS')).toBeInTheDocument(); | ||
expect(screen.getByText('contract.DAY_OFF')).toBeInTheDocument(); | ||
expect(screen.getByText('contract.SALARY')).toBeInTheDocument(); | ||
expect(screen.getByText('contract.ANNUAL_PAID_LEAVE')).toBeInTheDocument(); | ||
expect(screen.getByText('contract.RULE')).toBeInTheDocument(); | ||
}); | ||
|
||
it('์๋ช ํ์ง ์๊ณ ์ ์ถํ๋ฉด ๋ฉ์ธ์ง๋ฅผ ๋์ด๋ค.', async () => { | ||
const { getByRole } = renderContract(); | ||
|
||
fireEvent.click(getByRole('button', { name: 'contract.SUBMIT' })); | ||
|
||
await vi.waitFor(() => { | ||
const errorMessage = screen.getByText('contract.ERROR.SIGN'); | ||
expect(errorMessage).toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
it('์๋ช ํ ์ ์ถํ๋ค.', async () => { | ||
const { getByRole } = renderContract(); | ||
|
||
fireEvent.click(getByRole('button', { name: 'contract.SIGN' })); | ||
fireEvent.click(getByRole('button', { name: 'contract.SUBMIT' })); | ||
|
||
await vi.waitFor(() => { | ||
expect(mockNavigate).toHaveBeenCalledWith(ROUTE_PATH.HOME); | ||
}); | ||
}); | ||
}); |
153 changes: 153 additions & 0 deletions
153
src/features/contract/EmployeeContract/components/ContractSection.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,153 @@ | ||
import { useState } from 'react'; | ||
import { useGetMyContract } from '@/apis/contract/hooks/useGetMyContract'; | ||
import { Button, Typo } from '@/components/common'; | ||
import ROUTE_PATH from '@/routes/path'; | ||
import styled from '@emotion/styled'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { useNavigate, useParams } from 'react-router-dom'; | ||
import { usePostSignEmployeeContract } from '@/apis/contract/hooks/usePostEmployeeSign'; | ||
|
||
export type ContractResponseData = { | ||
salary: string; | ||
workingHours: string; | ||
dayOff: string; | ||
annualPaidLeave: string; | ||
workingPlace: string; | ||
responsibilities: string; | ||
rule: string; | ||
}; | ||
|
||
export default function ContractSection() { | ||
const { t } = useTranslation(); | ||
const { applyId } = useParams(); | ||
const applicationId = Number(applyId); | ||
const { data: contract } = useGetMyContract(applicationId); | ||
const mutation = usePostSignEmployeeContract(); | ||
const navigate = useNavigate(); | ||
const contractData: ContractResponseData = contract || {}; | ||
|
||
const [isSigned, setIsSigned] = useState(false); | ||
const [showSignError, setShowSignError] = useState(false); | ||
|
||
const handlePostSignEmployeeContract = () => { | ||
if (!isSigned) { | ||
setShowSignError(true); | ||
return; | ||
} | ||
mutation.mutate( | ||
{ applyId: applicationId }, | ||
{ | ||
onSuccess: () => { | ||
navigate(ROUTE_PATH.HOME); | ||
}, | ||
onError: () => { | ||
alert('๊ฐ์ด ์ ์์ ์ผ๋ก ์ ์ฅ๋์ง ์์์ต๋๋ค.'); | ||
}, | ||
}, | ||
); | ||
}; | ||
|
||
const handleSign = () => { | ||
setIsSigned(!isSigned); | ||
setShowSignError(false); | ||
}; | ||
|
||
return ( | ||
<> | ||
<InputWrapper> | ||
<InputContainer> | ||
<Typo>{t('contract.WORKING_PLACE')}</Typo> | ||
<Typo>{contractData.workingPlace}</Typo> | ||
</InputContainer> | ||
<InputContainer> | ||
<Typo>{t('contract.RESPONSIBILITIES')}</Typo> | ||
<Typo>{contractData.responsibilities}</Typo> | ||
</InputContainer> | ||
<InputContainer> | ||
<Typo>{t('contract.WORKING_HOURS')}</Typo> | ||
<Typo>{contractData.workingHours}</Typo> | ||
</InputContainer> | ||
<InputContainer> | ||
<Typo>{t('contract.DAY_OFF')}</Typo> | ||
<Typo>{contractData.dayOff}</Typo> | ||
</InputContainer> | ||
<InputContainer> | ||
<Typo>{t('contract.SALARY')}</Typo> | ||
<Typo>{contractData.salary}</Typo> | ||
</InputContainer> | ||
<InputContainer> | ||
<Typo>{t('contract.ANNUAL_PAID_LEAVE')}</Typo> | ||
<Typo>{contractData.annualPaidLeave}</Typo> | ||
</InputContainer> | ||
<InputContainer> | ||
<Typo>{t('contract.RULE')}</Typo> | ||
<Typo>{contractData.rule}</Typo> | ||
</InputContainer> | ||
</InputWrapper> | ||
<Typo element="p" size="16px" style={{ fontWeight: 'bold', marginTop: '24px' }}> | ||
{t('contract.SENTENCE1')} | ||
</Typo> | ||
<Typo element="p" size="16px" style={{ fontWeight: 'bold', marginTop: '24px' }}> | ||
{t('contract.SENTENCE2')} | ||
</Typo> | ||
<ButtonWrapper> | ||
<SignButton design="outlined" isSigned={isSigned} onClick={handleSign}> | ||
<TypoWrapper isSigned={isSigned}>{t('contract.SIGN')}</TypoWrapper> | ||
{isSigned && <CheckIcon>โ </CheckIcon>} | ||
</SignButton> | ||
<Button design="default" onClick={handlePostSignEmployeeContract}> | ||
{t('contract.SUBMIT')} | ||
</Button> | ||
</ButtonWrapper> | ||
{showSignError && !isSigned && <ErrorText>{t('contract.ERROR.SIGN')}</ErrorText>} | ||
</> | ||
); | ||
} | ||
|
||
const InputWrapper = styled.div` | ||
margin-top: 28px; | ||
`; | ||
|
||
const InputContainer = styled.div` | ||
width: 700px; | ||
display: flex; | ||
align-items: center; | ||
justify-content: space-between; | ||
margin: 24px 0; | ||
`; | ||
|
||
const ButtonWrapper = styled.div` | ||
width: 700px; | ||
display: flex; | ||
align-items: center; | ||
justify-content: space-between; | ||
margin-top: 52px; | ||
`; | ||
|
||
const SignButton = styled(Button)<{ isSigned: boolean }>` | ||
width: 150px; | ||
background-color: ${({ isSigned }) => (isSigned ? '#3960d7' : 'white')}; | ||
color: ${({ isSigned }) => (isSigned ? 'white' : 'black')}; | ||
padding: 10px 0; | ||
display: flex; | ||
align-items: center; | ||
transition: | ||
background-color 0.3s, | ||
color 0.3s; | ||
`; | ||
|
||
const TypoWrapper = styled.span<{ isSigned: boolean }>` | ||
margin-right: ${({ isSigned }) => (isSigned ? '8px' : '0')}; | ||
transition: margin-right 0.3s; | ||
`; | ||
|
||
const CheckIcon = styled.span` | ||
transition: opacity 0.3s; | ||
opacity: 1; | ||
`; | ||
|
||
const ErrorText = styled.span` | ||
color: red; | ||
font-size: 12px; | ||
margin-top: 8px; | ||
`; |
Oops, something went wrong.