2023-09-25 20:19:56 +00:00
|
|
|
import moment from 'moment';
|
2023-08-20 05:23:15 +00:00
|
|
|
import * as yup from 'yup';
|
2023-09-25 20:31:25 +00:00
|
|
|
import { UNIT_TYPES } from './constants';
|
2023-08-20 05:23:15 +00:00
|
|
|
|
2023-09-25 20:19:56 +00:00
|
|
|
export const DateRangeValidation = {
|
|
|
|
|
startAt: yup.number().integer().required(),
|
|
|
|
|
endAt: yup.number().integer().moreThan(yup.ref('startAt')).required(),
|
|
|
|
|
};
|
2023-08-20 05:23:15 +00:00
|
|
|
|
|
|
|
|
// ex: /funnel|insights|retention/i
|
|
|
|
|
export function getFilterValidation(matchRegex) {
|
|
|
|
|
return {
|
|
|
|
|
filter: yup.string(),
|
|
|
|
|
filterType: yup.string().matches(matchRegex),
|
|
|
|
|
pageSize: yup.number().integer().positive().max(200),
|
|
|
|
|
page: yup.number().integer().positive(),
|
|
|
|
|
orderBy: yup.string(),
|
|
|
|
|
};
|
|
|
|
|
}
|
2023-09-25 20:19:56 +00:00
|
|
|
|
|
|
|
|
export const TimezoneTest = yup.string().test(
|
|
|
|
|
'timezone',
|
|
|
|
|
() => `Invalid timezone`,
|
2023-09-25 20:31:25 +00:00
|
|
|
value => !value || !moment.tz.zone(value),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
export const UnitTypeTest = yup.string().test(
|
|
|
|
|
'unit',
|
|
|
|
|
() => `Invalid unit`,
|
|
|
|
|
value => !value || !UNIT_TYPES.includes(value),
|
2023-09-25 20:19:56 +00:00
|
|
|
);
|