fix: restrict delete button to admins
This commit is contained in:
5
src/utils/configUtils.js
Normal file
5
src/utils/configUtils.js
Normal file
@@ -0,0 +1,5 @@
|
||||
export const sortEntriesByLabel = (entries = []) => {
|
||||
return [...entries].sort((a, b) =>
|
||||
(a?.label || '').localeCompare(b?.label || '', 'de', { sensitivity: 'base' })
|
||||
);
|
||||
};
|
||||
51
src/utils/dateUtils.js
Normal file
51
src/utils/dateUtils.js
Normal file
@@ -0,0 +1,51 @@
|
||||
import { format, parseISO, isValid, startOfDay } from 'date-fns';
|
||||
import { de } from 'date-fns/locale';
|
||||
|
||||
export const parseDateValue = (value) => {
|
||||
if (!value) {
|
||||
return null;
|
||||
}
|
||||
const parsed = parseISO(value);
|
||||
return isValid(parsed) ? parsed : null;
|
||||
};
|
||||
|
||||
export const formatDateValue = (date) => {
|
||||
if (!(date instanceof Date) || !isValid(date)) {
|
||||
return null;
|
||||
}
|
||||
return format(date, 'yyyy-MM-dd');
|
||||
};
|
||||
|
||||
export const formatRangeLabel = (start, end) => {
|
||||
const startDate = parseDateValue(start);
|
||||
const endDate = parseDateValue(end);
|
||||
if (startDate && endDate) {
|
||||
const startLabel = format(startDate, 'dd.MM.yyyy', { locale: de });
|
||||
const endLabel = format(endDate, 'dd.MM.yyyy', { locale: de });
|
||||
if (startLabel === endLabel) {
|
||||
return startLabel;
|
||||
}
|
||||
return `${startLabel} – ${endLabel}`;
|
||||
}
|
||||
if (startDate) {
|
||||
return format(startDate, 'dd.MM.yyyy', { locale: de });
|
||||
}
|
||||
return 'Zeitraum auswählen';
|
||||
};
|
||||
|
||||
export const buildSelectionRange = (start, end, minDate) => {
|
||||
const minimum = minDate || startOfDay(new Date());
|
||||
let startDate = parseDateValue(start) || parseDateValue(end) || minimum;
|
||||
let endDate = parseDateValue(end) || parseDateValue(start) || startDate;
|
||||
if (startDate < minimum) {
|
||||
startDate = minimum;
|
||||
}
|
||||
if (endDate < minimum) {
|
||||
endDate = startDate;
|
||||
}
|
||||
return {
|
||||
startDate,
|
||||
endDate,
|
||||
key: 'selection'
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user