260722_01_ENH: 버그 수정 및 개선 사항 수정
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { ListHeaderAssignConst, ListHeaderConst } from "@/const/listConst";
|
||||
import { CONTACT_INTERVIEWER_ROLE, FIELD_INTERVIEWER_ROLE } from "@/const/userConst";
|
||||
import { ListIsUse, type ListFilter, type listHeader } from "@/types/list";
|
||||
import { isExternalManager, isFieldWorkUser, isInternalManager } from "@/utils/userRole";
|
||||
import {isExternalManager, isFieldWorkUser, isInternalManager, isManager} from "@/utils/userRole";
|
||||
|
||||
type ListAccessUser = {
|
||||
userRole?: number | null;
|
||||
@@ -23,9 +23,9 @@ export const isListFilterVisibleByAccess = (header: listHeader, userRole?: numbe
|
||||
// 컨택 진행 화면(/list/contact)은 역할과 무관하게 면접원 노출 항목만 보여준다.
|
||||
export const isListFieldVisibleForContact = (header: listHeader) => header.useIntrvwerView;
|
||||
|
||||
// SID는 항상 읽기 전용. internal 권한은 그 외 전부 수정 가능, 그 외 역할은 헤더별 면접원 수정가능 여부를 따른다.
|
||||
// SID는 항상 읽기 전용. manager 권한은 그 외 전부 수정 가능, 그 외 역할은 헤더별 면접원 수정가능 여부를 따른다.
|
||||
export const isListFieldEditableForContact = (header: listHeader, userRole?: number | null) =>
|
||||
header.listHderTy !== ListHeaderConst.SID && (isInternalManager(userRole) || header.useIntrvwerEdit);
|
||||
header.listHderTy !== ListHeaderConst.SID && (isManager(userRole) || header.useIntrvwerEdit);
|
||||
|
||||
export const getLockedListFilterHeaderTypes = (userRole?: number | null) => {
|
||||
const lockedTypes = new Set<number>();
|
||||
|
||||
50
src/utils/validation.ts
Normal file
50
src/utils/validation.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
export interface ValidateOptions {
|
||||
/** 값이 비어있으면(trim 후 빈 문자열) 실패 처리 */
|
||||
required?: boolean
|
||||
requiredMessage?: string
|
||||
/** 최소 길이(trim 후 기준) */
|
||||
minLength?: number
|
||||
/** 최대 길이(trim 후 기준) */
|
||||
maxLength?: number
|
||||
lengthMessage?: string
|
||||
/** 형식 검증용 정규식(trim 후 값에 대해 test) */
|
||||
pattern?: RegExp
|
||||
patternMessage?: string
|
||||
}
|
||||
|
||||
export interface ValidateResult {
|
||||
valid: boolean
|
||||
message?: string
|
||||
}
|
||||
|
||||
const DEFAULT_REQUIRED_MESSAGE = '값을 입력해주세요.'
|
||||
const DEFAULT_PATTERN_MESSAGE = '형식이 올바르지 않습니다.'
|
||||
|
||||
/**
|
||||
* 값이 비었는지 / 길이가 맞는지 / 정규식에 맞는지를 옵션으로 선택해서 검사한다.
|
||||
* 빈 값이고 required가 아니면 나머지 검사는 건너뛰고 통과 처리한다.
|
||||
*/
|
||||
export function validateValue(value: string, options: ValidateOptions): ValidateResult {
|
||||
const trimmed = value.trim()
|
||||
|
||||
if (!trimmed) {
|
||||
if (options.required) {
|
||||
return { valid: false, message: options.requiredMessage ?? DEFAULT_REQUIRED_MESSAGE }
|
||||
}
|
||||
return { valid: true }
|
||||
}
|
||||
|
||||
if (options.minLength !== undefined && trimmed.length < options.minLength) {
|
||||
return { valid: false, message: options.lengthMessage ?? `${options.minLength}자 이상 입력해주세요.` }
|
||||
}
|
||||
|
||||
if (options.maxLength !== undefined && trimmed.length > options.maxLength) {
|
||||
return { valid: false, message: options.lengthMessage ?? `${options.maxLength}자 이하로 입력해주세요.` }
|
||||
}
|
||||
|
||||
if (options.pattern && !options.pattern.test(trimmed)) {
|
||||
return { valid: false, message: options.patternMessage ?? DEFAULT_PATTERN_MESSAGE }
|
||||
}
|
||||
|
||||
return { valid: true }
|
||||
}
|
||||
Reference in New Issue
Block a user