98 lines
2.3 KiB
TypeScript
98 lines
2.3 KiB
TypeScript
import { CollectionConfig } from "payload";
|
|
import { requirePermission } from "@/utils/access-control/hasPermission";
|
|
|
|
export const Assignments: CollectionConfig = {
|
|
slug: "assignments",
|
|
admin: {
|
|
group: "Users",
|
|
useAsTitle: "name",
|
|
},
|
|
access: {
|
|
create: requirePermission("assignments:create"),
|
|
update: requirePermission("assignments:update"),
|
|
delete: requirePermission("assignments:delete"),
|
|
},
|
|
fields: [
|
|
{
|
|
name: "name",
|
|
type: "text",
|
|
required: true,
|
|
},
|
|
{
|
|
name: "type",
|
|
type: "select",
|
|
options: [
|
|
{
|
|
label: "Division",
|
|
value: "division",
|
|
},
|
|
{
|
|
label: "Squad",
|
|
value: "squad",
|
|
},
|
|
{
|
|
label: "Team",
|
|
value: "team",
|
|
},
|
|
{
|
|
label: "Special",
|
|
value: "special",
|
|
},
|
|
],
|
|
required: true,
|
|
},
|
|
{
|
|
name: "callsign",
|
|
type: "text",
|
|
},
|
|
{
|
|
name: "description",
|
|
type: "richText",
|
|
},
|
|
{
|
|
name: "leader",
|
|
type: "relationship",
|
|
relationTo: "users",
|
|
admin: {
|
|
description:
|
|
"The leader represents the individual responsible for this assignment and its members. The leader automatically counts as a member when this assignment is queried.",
|
|
},
|
|
},
|
|
{
|
|
name: "commandElement",
|
|
type: "join",
|
|
collection: "assignments",
|
|
on: "subAssignments",
|
|
admin: {
|
|
allowCreate: false,
|
|
condition: (data) => {
|
|
const hasCommandElement = data?.commandElement?.docs;
|
|
return Array.isArray(hasCommandElement)
|
|
? hasCommandElement.length > 0
|
|
: Boolean(hasCommandElement);
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "subAssignments",
|
|
type: "relationship",
|
|
relationTo: "assignments",
|
|
hasMany: true,
|
|
admin: {
|
|
description: "Add other teams as members of this team/assignment.",
|
|
},
|
|
},
|
|
{
|
|
name: "members",
|
|
type: "relationship",
|
|
relationTo: "users",
|
|
hasMany: true,
|
|
admin: {
|
|
components: {
|
|
Field: "@/components/admin/assignments/AssignmentMembersField",
|
|
},
|
|
description: "Add individuals as members of this team/assignment.",
|
|
},
|
|
},
|
|
],
|
|
};
|