Skip to content

Instantly share code, notes, and snippets.

@kimumu-asia
Created August 10, 2023 06:35
Show Gist options
  • Save kimumu-asia/fd5a14f1fa3af12c84127b59b8398bc9 to your computer and use it in GitHub Desktop.
Save kimumu-asia/fd5a14f1fa3af12c84127b59b8398bc9 to your computer and use it in GitHub Desktop.
yup schema 모음
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),
};
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