35 lines
671 B
JavaScript
35 lines
671 B
JavaScript
import { parseYMD } from './date';
|
|
|
|
export function validateTripDraft({ name = '', startDate = '', endDate = '' }) {
|
|
if (!`${name || ''}`.trim()) {
|
|
return {
|
|
valid: false,
|
|
title: 'Missing name',
|
|
message: 'Trip name is required.',
|
|
};
|
|
}
|
|
|
|
const start = parseYMD(startDate);
|
|
const end = parseYMD(endDate);
|
|
|
|
if (!start || !end) {
|
|
return {
|
|
valid: false,
|
|
title: 'Invalid dates',
|
|
message: 'Please select valid trip dates.',
|
|
};
|
|
}
|
|
|
|
if (start > end) {
|
|
return {
|
|
valid: false,
|
|
title: 'Invalid dates',
|
|
message: 'Start date cannot be after end date.',
|
|
};
|
|
}
|
|
|
|
return {
|
|
valid: true,
|
|
};
|
|
}
|