disable edits for published dates if not admin
This commit is contained in:
@ -21,8 +21,10 @@ import CartEventForm from "components/cartevent/CartEventForm";
|
||||
interface IProps {
|
||||
initialItems: Availability[];
|
||||
initialUserId: string;
|
||||
cartEvents: any;
|
||||
lastPublishedDate: Date;
|
||||
}
|
||||
export default function IndexPage({ initialItems, initialUserId, cartEvents }: IProps) {
|
||||
export default function IndexPage({ initialItems, initialUserId, cartEvents, lastPublishedDate }: IProps) {
|
||||
const { data: session } = useSession();
|
||||
const [userName, setUserName] = useState(session?.user?.name);
|
||||
const [userId, setUserId] = useState(initialUserId);
|
||||
@ -79,7 +81,7 @@ export default function IndexPage({ initialItems, initialUserId, cartEvents }: I
|
||||
<div className="text-center font-bold pb-3 xs:pb-1">
|
||||
<PublisherInlineForm publisherId={userId} />
|
||||
</div>
|
||||
<AvCalendar publisherId={userId} events={events} selectedDate={new Date()} cartEvents={cartEvents} />
|
||||
<AvCalendar publisherId={userId} events={events} selectedDate={new Date()} cartEvents={cartEvents} lastPublishedDate={lastPublishedDate} />
|
||||
</div>
|
||||
</div>
|
||||
</ProtectedRoute>
|
||||
@ -229,6 +231,7 @@ export const getServerSideProps = async (context) => {
|
||||
startTime: updatedItem.shift.startTime.toISOString(),
|
||||
endTime: updatedItem.shift.endTime.toISOString()
|
||||
};
|
||||
updatedItem.isPublished = updatedItem.shift.isPublished;
|
||||
}
|
||||
|
||||
return updatedItem;
|
||||
@ -239,6 +242,7 @@ export const getServerSideProps = async (context) => {
|
||||
console.log("First availability startTime: " + items[0]?.startTime);
|
||||
console.log("First availability startTime: " + items[0]?.startTime.toLocaleString());
|
||||
|
||||
|
||||
const prisma = common.getPrismaClient();
|
||||
let cartEvents = await prisma.cartEvent.findMany({
|
||||
where: {
|
||||
@ -253,11 +257,23 @@ export const getServerSideProps = async (context) => {
|
||||
}
|
||||
});
|
||||
cartEvents = common.convertDatesToISOStrings(cartEvents);
|
||||
const lastPublishedDate = (await prisma.shift.findFirst({
|
||||
where: {
|
||||
isPublished: true,
|
||||
},
|
||||
select: {
|
||||
endTime: true,
|
||||
},
|
||||
orderBy: {
|
||||
endTime: 'desc'
|
||||
}
|
||||
})).endTime;
|
||||
return {
|
||||
props: {
|
||||
initialItems: items,
|
||||
userId: sessionServer?.user.id,
|
||||
cartEvents: cartEvents,
|
||||
lastPublishedDate: lastPublishedDate.toISOString(),
|
||||
// messages: (await import(`../content/i18n/${context.locale}.json`)).default
|
||||
},
|
||||
};
|
||||
|
Reference in New Issue
Block a user