Created
August 10, 2023 06:35
-
-
Save kimumu-asia/fd5a14f1fa3af12c84127b59b8398bc9 to your computer and use it in GitHub Desktop.
yup schema 모음
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
import * as yup from 'yup'; | |
import { | |
IMAGE_APP_REQUIRED_MESSAGE, | |
STATION_NAME_EXCEED_MAX_LENGTH_MESSAGE, | |
STATION_NAME_REQUIRED_MESSAGE, | |
TYPE_NUMBER_REQUIRED_MESSAGE, | |
WEIGHTED_REQUIRED_MESSAGE, | |
} from '#/common/const/errorMessages'; | |
import { MAX_LENGTH } from '#/ManagementGroup/const/SmartStation/SmartStation'; | |
export const stationFormSchema = yup.object().shape({ | |
name: yup | |
.string() | |
.required(STATION_NAME_REQUIRED_MESSAGE) | |
.max(MAX_LENGTH.STATION_NAME, STATION_NAME_EXCEED_MAX_LENGTH_MESSAGE), | |
imageApp: yup.lazy((value) => { | |
return Array.isArray(value) | |
? yup.array().min(1, IMAGE_APP_REQUIRED_MESSAGE) | |
: yup | |
.string(IMAGE_APP_REQUIRED_MESSAGE) | |
.typeError(IMAGE_APP_REQUIRED_MESSAGE) | |
.required(IMAGE_APP_REQUIRED_MESSAGE); | |
}), | |
}); | |
export const stationSingleUpdateSchema = { | |
weighted: yup.number(TYPE_NUMBER_REQUIRED_MESSAGE).max(30).required(WEIGHTED_REQUIRED_MESSAGE), | |
}; |
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
export const timeSchema = yup.object().shape({ | |
startTime: yup.string().required('시작시간을 입력하세요'), | |
endTime: yup | |
.string() | |
.required('종료시간을 입력하세요') | |
.test('is-greater', '종료시간은 시작시간 이후로 설정하세요', (value) => { | |
const { startTime } = this.parent; | |
return moment(value, 'HH:mm').isSameOrAfter(moment(startTime, 'HH:mm')); | |
}), | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment