Skip to content
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

πŸ› Fix/127 - μ„œλ₯˜μƒμ„±λ‘œλ”©μ²˜λ¦¬,μœ νš¨μ„±κ²€μ‚¬κ°•ν™” #158

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions src/components/Document/DocumentCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type DocumentCardProps = {
title: string;
type: string;
onNext?: () => void;
setIsLoading: (value: boolean) => void;
};

const TemporarySaveCard = ({
Expand Down Expand Up @@ -331,9 +332,24 @@ const DocumentCardDispenser = ({
documentInfo,
title,
type,
setIsLoading,
}: DocumentCardProps) => {
const { mutate: submitDocument } = usePatchStatusSubmission();
const { mutate: confirmDocument } = usePatchDocumentsStatusConfirmation();
const { mutate: submitDocument } = usePatchStatusSubmission({
onMutate: () => {
setIsLoading(true);
},
onSettled: () => {
setIsLoading(false);
},
});
const { mutate: confirmDocument } = usePatchDocumentsStatusConfirmation({
onMutate: () => {
setIsLoading(true);
},
onSettled: () => {
setIsLoading(false);
},
});
const navigate = useNavigate();
const { updateCurrentDocumentId } = useCurrentDocumentIdStore();
const handleDownload = (url: string) => {
Expand Down
55 changes: 35 additions & 20 deletions src/components/Document/DocumentCardList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ import {
usePatchDocumentsStatusConfirmation,
usePatchStatusSubmission,
} from '@/hooks/api/useDocument';
import { useState } from 'react';
import LoadingItem from '../Common/LoadingItem';

const DocumentCardList = ({
documents,
}: {
documents: DocumentsSummaryResponse;
}) => {
const documentTypes = Object.values(DocumentType);
const [isLoading, setIsLoading] = useState(false);
// patch api mutate μ„€μ • (8.15 μœ ν•™μƒμ΄ μ„œλ₯˜ μ œμΆœν•˜κΈ°)
const { mutate: patchStatusSubmission } = usePatchStatusSubmission();

Expand All @@ -31,27 +34,39 @@ const DocumentCardList = ({
};

return (
<div className="flex flex-col w-full px-6 gap-2 pb-[8rem]">
{documentTypes.map((property, index) =>
documents[property] ? (
<DocumentCardDispenser
key={`${index}_${property}`}
documentInfo={documents[property]}
title={DocumentTypeInfo[property].name}
type={property}
// null 체크 μΆ”κ°€
onNext={() => {
const document = documents[property];
if (document && document.status) {
handleOnNext(document.id, document.status);
}
}}
/>
) : (
<MakeDocumentButton type={property} key={`${index}_${property}`} />
),
<>
{isLoading && (
<div
className="fixed inset-0 z-50 flex items-center justify-center bg-white bg-opacity-50 overflow-hidden"
style={{ touchAction: 'none' }}
onClick={(e) => e.preventDefault()}
>
<LoadingItem />
</div>
)}
</div>
<div className="flex flex-col w-full px-6 gap-2 pb-[8rem]">
{documentTypes.map((property, index) =>
documents[property] ? (
<DocumentCardDispenser
key={`${index}_${property}`}
documentInfo={documents[property]}
title={DocumentTypeInfo[property].name}
type={property}
// null 체크 μΆ”κ°€
onNext={() => {
const document = documents[property];
if (document && document.status) {
handleOnNext(document.id, document.status);
}
}}
setIsLoading={(value: boolean) => setIsLoading(value)}
/>
) : (
<MakeDocumentButton type={property} key={`${index}_${property}`} />
),
)}
</div>
</>
);
};

Expand Down
13 changes: 5 additions & 8 deletions src/components/Information/StepIndicator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,20 @@ const StepIndicator = ({
length = 3,
currentStep = 1,
mainColor = '#FEF387',
backgroundColor = '#F4F4F9',
backgroundColor = '#FFFFFF',
borderColor = '#F4F4F9',
textColor = '#ffffff',
textColor = '#222',
inactiveTextColor = '#BDBDBD',
}: StepIndicatorProps) => {
const steps = Array.from({ length }, (_, i) => i + 1);

return (
<div
className="relative w-full flex flex-row items-center justify-center text-center body-3"
>
<div className="relative w-full flex flex-row items-center justify-center text-center body-3">
{steps.map((step, index) => (
<React.Fragment key={step}>
{/* Step Circle */}
<div
className="relative flex items-center justify-center w-6 h-6"
style={{
color: textColor ,
}}
>
<div
className="flex items-center justify-center w-5 h-5 rounded-full"
Expand All @@ -40,6 +36,7 @@ const StepIndicator = ({
currentStep >= step ? mainColor : backgroundColor,
border:
currentStep >= step ? 'none' : `1px solid ${borderColor}`,
color: currentStep >= step ? textColor : inactiveTextColor,
}}
>
{step}
Expand Down
9 changes: 6 additions & 3 deletions src/components/WriteDocuments/PartTimePermitWriteForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { phone } from '@/constants/information';
import EmployerInfoSection from '@/components/Document/write/EmployerInfoSection';
import BottomButtonPanel from '@/components/Common/BottomButtonPanel';
import Button from '@/components/Common/Button';
import { isNotEmpty } from '@/utils/document';
import { validatePartTimePermit } from '@/utils/document';
import { formatPhoneNumber, parsePhoneNumber } from '@/utils/information';
import {
usePostPartTimeEmployPermit,
Expand Down Expand Up @@ -265,8 +265,11 @@ const PartTimePermitWriteForm = ({
</div>

<BottomButtonPanel>
{/* μž…λ ₯된 정보 쀑 빈 칸이 μ—†λ‹€λ©΄ ν™œμ„±ν™” */}
{isNotEmpty(newDocumentData) && isNotEmpty(phoneNum) ? (
{/* μž…λ ₯된 μ •λ³΄μ˜ μœ νš¨μ„± 검사 톡과 μ‹œ ν™œμ„±ν™” */}
{validatePartTimePermit({
...newDocumentData,
phone_number: formatPhoneNumber(phoneNum),
}) ? (
<Button
type="large"
bgColor="bg-[#fef387]"
Expand Down
20 changes: 11 additions & 9 deletions src/hooks/api/useDocument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,9 @@ export const usePutIntegratedApplicants = (
};

// 8.15 (μœ ν•™μƒ) μ„œλ₯˜ (κ·Όλ‘œκ³„μ•½μ„œ, μ‹œκ°„μ œ μ·¨μ—…ν—ˆκ°€μ„œ, 톡합 μ‹ μ²­μ„œ) μ œμΆœν•˜κΈ° api hook
export const usePatchStatusSubmission = () => {
export const usePatchStatusSubmission = (
options?: UseMutationOptions<RESTYPE<null>, Error, number>,
) => {
return useMutation({
mutationFn: patchStatusSubmission,
onSuccess: () => {
Expand All @@ -265,16 +267,13 @@ export const usePatchStatusSubmission = () => {
onError: (error) => {
console.error('μœ ν•™μƒμ˜ μ„œλ₯˜ 제좜 μ‹€νŒ¨', error);
},
...options,
});
};

// 8.16 (고용주) μ„œλ₯˜ (κ·Όλ‘œκ³„μ•½μ„œ, μ‹œκ°„μ œ μ·¨μ—…ν—ˆκ°€μ„œ, 톡합 μ‹ μ²­μ„œ) μ œμΆœν•˜κΈ° api hook
export const usePatchStatusSubmissionEmployer = (
options?: UseMutationOptions<
RESTYPE<null>,
Error,
number
>,
options?: UseMutationOptions<RESTYPE<null>, Error, number>,
) => {
return useMutation({
mutationFn: patchStatusSubmissionEmployer,
Expand All @@ -284,12 +283,14 @@ export const usePatchStatusSubmissionEmployer = (
onError: (error) => {
console.error('고용주의 μ„œλ₯˜ 제좜 μ‹€νŒ¨', error);
},
...options
...options,
});
};

// 8.17 (μœ ν•™μƒ) μ„œλ₯˜ (κ·Όλ‘œκ³„μ•½μ„œ, μ‹œκ°„μ œ μ·¨μ—…ν—ˆκ°€μ„œ) μ»΄νŽŒν•˜κΈ°
export const usePatchDocumentsStatusConfirmation = () => {
// 8.17 (μœ ν•™μƒ) μ„œλ₯˜ (κ·Όλ‘œκ³„μ•½μ„œ, μ‹œκ°„μ œ μ·¨μ—…ν—ˆκ°€μ„œ) μ»¨νŽŒν•˜κΈ°
export const usePatchDocumentsStatusConfirmation = (
options?: UseMutationOptions<RESTYPE<null>, Error, number>,
) => {
return useMutation({
mutationFn: patchDocumentsStatusConfirmation,
onSuccess: () => {
Expand All @@ -298,6 +299,7 @@ export const usePatchDocumentsStatusConfirmation = () => {
onError: (error) => {
console.error('μœ ν•™μƒμ˜ μ„œλ₯˜ 컨펌 μ‹€νŒ¨', error);
},
...options,
});
};

Expand Down
56 changes: 51 additions & 5 deletions src/utils/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ import {
Insurance,
IntegratedApplicationData,
LaborContractEmployerInfo,
PartTimePermitFormRequest,
WorkDayTime,
} from '@/types/api/document';
import { Address } from '@/types/api/users';
import { extractNumbersAsNumber } from './post';
import { InsuranceInfo } from '@/constants/documents';
import { isValidPhoneNumber, parsePhoneNumber } from './information';
import { parsePhoneNumber } from './information';

export const MINIMUM_HOURLY_RATE = 10030;

Expand All @@ -31,6 +32,51 @@ export const isNotEmpty = (obj: Record<string, any>): boolean => {
});
};

// string data의 곡백 μ—¬λΆ€λ₯Ό ν™•μΈν•˜λŠ” ν•¨μˆ˜
const hasStringValue = (value: string): boolean => {
return value.trim().length > 0;
};

// 이메일 μœ νš¨μ„± 검사 ν•¨μˆ˜
const isEmailValid = (email: string): boolean => {
const emailRegex = /^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$/;
return emailRegex.test(email);
};

// μ „ν™”λ²ˆν˜Έ μœ νš¨μ„± 검사 ν•¨μˆ˜
const isValidPhoneNumber = (phone: string) => {
const phoneNum = parsePhoneNumber(phone);
return (
phoneNum.start !== '' &&
/^[0-9]{4}$/.test(phoneNum.middle) &&
/^[0-9]{4}$/.test(phoneNum.end)
);
};

// μ΄μˆ˜ν•™κΈ° μœ νš¨μ„± 검사 ν•¨μˆ˜
const isValidTermOfCompletion = (term: number): boolean => {
return !isNaN(term) && term > 0;
};

// (μœ ν•™μƒ) μ‹œκ°„μ œ 근둜 ν—ˆκ°€μ„œ μœ νš¨μ„± 검사 ν•¨μˆ˜
export const validatePartTimePermit = (
data: PartTimePermitFormRequest,
): boolean => {
// ν•„μˆ˜ μž…λ ₯ ν•­λͺ© 체크(이름, μ„±, μ „ν™”λ²ˆν˜Έ, 이메일, μ΄μˆ˜ν•™κΈ°, μ „ν™”λ²ˆν˜Έ)
if (
hasStringValue(data.first_name) &&
hasStringValue(data.last_name) &&
hasStringValue(data.phone_number) &&
isEmailValid(data.email) &&
isValidPhoneNumber(data.phone_number) &&
isValidTermOfCompletion(data.term_of_completion)
) {
return true;
}

return false;
};

export const workDayTimeToString = (workDayTimes: WorkDayTime[]): string => {
// μš”μΌλ§Œ μΆ”μΆœν•˜μ—¬ λ°°μ—΄λ‘œ λ§Œλ“€κΈ°
const daysOfWeek = workDayTimes.map((wdt) => wdt.day_of_week);
Expand Down Expand Up @@ -239,10 +285,10 @@ export const validateIntegratedApplication = (

// μ „ν™”λ²ˆν˜Έ ν•„λ“œλ“€ 검사
const isPhoneValid =
isValidPhoneNumber(parsePhoneNumber(data.tele_phone_number)) &&
isValidPhoneNumber(parsePhoneNumber(data.cell_phone_number)) &&
isValidPhoneNumber(parsePhoneNumber(data.school_phone_number)) &&
isValidPhoneNumber(parsePhoneNumber(data.new_work_place_phone_number));
isValidPhoneNumber(data.tele_phone_number) &&
isValidPhoneNumber(data.cell_phone_number) &&
isValidPhoneNumber(data.school_phone_number) &&
isValidPhoneNumber(data.new_work_place_phone_number);
// λ‚˜λ¨Έμ§€ ν•„λ“œ 검사
const otherFieldsValid = Object.entries(data).every(([key, value]) => {
// μ•žμ„œ κ²€μ‚¬ν•œ ν•„λ“œλ“€μ€ μŠ€ν‚΅
Expand Down