⬆️ v3.0.0 (#704)

This commit is contained in:
Luke Vella 2023-06-19 17:17:00 +01:00 committed by GitHub
parent 735056f25f
commit c22b3abc4d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
385 changed files with 19912 additions and 5250 deletions

View file

@ -0,0 +1,47 @@
import React from "react";
import { useParticipants } from "@/components/participants-provider";
import { useUser } from "@/components/user-provider";
import { usePoll } from "@/contexts/poll";
import { useRole } from "@/contexts/role";
export const PermissionsContext = React.createContext<{
userId: string | null;
}>({
userId: null,
});
export const usePermissions = () => {
const poll = usePoll();
const context = React.useContext(PermissionsContext);
const { user } = useUser();
const role = useRole();
const { participants } = useParticipants();
const isClosed = poll.closed === true || poll.event !== null;
return {
canAddNewParticipant: !isClosed,
canEditParticipant: (participantId: string) => {
if (isClosed) {
return false;
}
if (role === "admin" && user.id === poll.userId) {
return true;
}
const participant = participants.find(
(participant) => participant.id === participantId,
);
if (
participant &&
(participant.userId === user.id ||
participant.userId === context.userId)
) {
return true;
}
return false;
},
};
};