disable edits for published dates if not admin
This commit is contained in:
@ -48,9 +48,19 @@ const messages = {
|
||||
// Any other labels you want to translate...
|
||||
};
|
||||
|
||||
const AvCalendar = ({ publisherId, events, selectedDate, cartEvents }) => {
|
||||
|
||||
const isAdmin = ProtectedRoute.IsInRole(UserRole.ADMIN);
|
||||
const AvCalendar = ({ publisherId, events, selectedDate, cartEvents, lastPublishedDate }) => {
|
||||
const [editLockedBefore, setEditLockedBefore] = useState(new Date(lastPublishedDate));
|
||||
const [isAdmin, setIsAdmin] = useState(false);
|
||||
useEffect(() => {
|
||||
(async () => {
|
||||
try {
|
||||
setIsAdmin(await ProtectedRoute.IsInRole(UserRole.ADMIN));
|
||||
} catch (error) {
|
||||
console.error("Failed to check admin role:", error);
|
||||
}
|
||||
})();
|
||||
}, []);
|
||||
//const isAdmin = ProtectedRoute.IsInRole(UserRole.ADMIN);
|
||||
|
||||
const [date, setDate] = useState(new Date());
|
||||
//ToDo: see if we can optimize this
|
||||
@ -227,6 +237,12 @@ const AvCalendar = ({ publisherId, events, selectedDate, cartEvents }) => {
|
||||
//readonly for past dates (ToDo: if not admin)
|
||||
if (!isAdmin) {
|
||||
if (startdate < new Date() || end < new Date() || startdate > end) return;
|
||||
//or if schedule is published (lastPublishedDate)
|
||||
if (editLockedBefore && startdate < editLockedBefore) {
|
||||
toast.error(`Не можете да променяте предпочитанията си за дати преди ${common.getDateFormatedShort(editLockedBefore)}.`, { autoClose: 5000 });
|
||||
return;
|
||||
|
||||
}
|
||||
}
|
||||
// Check if start and end are on the same day
|
||||
if (startdate.toDateString() !== enddate.toDateString()) {
|
||||
|
Reference in New Issue
Block a user