Skip to content

Commit

Permalink
add committee members and committees collections
Browse files Browse the repository at this point in the history
  • Loading branch information
MikaelSiidorow committed Feb 1, 2024
1 parent 1392a9b commit a51a118
Show file tree
Hide file tree
Showing 8 changed files with 3,412 additions and 1,152 deletions.
47 changes: 47 additions & 0 deletions apps/cms/src/collections/committees/committee-members.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import type { CollectionConfig } from "payload/types";
import { signedIn } from "../../access/signed-in";
import { guildYearField } from "../../fields/guild-year";

export const CommitteeMembers: CollectionConfig = {
slug: "committee-members",
defaultSort: "-guildYear",
admin: {
useAsTitle: "name",
},
access: {
read: () => true,
create: signedIn,
update: signedIn,
delete: signedIn,
},
fields: [
guildYearField({
name: "guildYear",
required: true,
}),
{
name: "photo",
type: "relationship",
relationTo: "media",
},
{
name: "name",
type: "text",
required: true,
},
{
name: "title",
type: "text",
required: true,
localized: true,
},
{
name: "chair",
type: "checkbox",
},
{
name: "telegramUsername",
type: "text",
},
],
};
57 changes: 57 additions & 0 deletions apps/cms/src/collections/committees/committees.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import type { Committee } from "@tietokilta/cms-types/payload";
import type { CollectionConfig, FilterOptions } from "payload/types";
import { signedIn } from "../../access/signed-in";
import { guildYearField } from "../../fields/guild-year";

const filterCurrentYear: FilterOptions<Committee> = ({ data }) => ({
guildYear: {
equals: data.year,
},
});

export const Committees: CollectionConfig = {
slug: "committees",
defaultSort: "-year",
admin: {
useAsTitle: "name",
defaultColumns: ["year", "name", "committeeMembers"],
},
access: {
read: () => true,
create: signedIn,
update: signedIn,
delete: signedIn,
},
fields: [
guildYearField({
name: "year",
required: true,
}),
{
name: "name",
type: "text",
required: true,
localized: true,
},
{
name: "description",
type: "richText",
localized: true,
required: true,
},
{
name: "committeeMembers",
type: "array",
required: true,
minRows: 1,
fields: [
{
name: "committeeMember",
type: "relationship",
relationTo: "committee-members",
filterOptions: filterCurrentYear,
},
],
},
],
};
1 change: 1 addition & 0 deletions apps/cms/src/fields/guild-year.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const guildYearField = (
hasMany: false,
...base,
type: "select",
defaultValue: `${currentYear}`,
options: Array.from(
{ length: currentYear - foundedYear + 1 },
(_, i) => `${currentYear - i}`,
Expand Down
13 changes: 12 additions & 1 deletion apps/cms/src/payload.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import { oAuthPlugin } from "payload-plugin-oauth";
import { buildConfig } from "payload/config";
import { BoardMembers } from "./collections/board/board-members";
import { Boards } from "./collections/board/boards";
import { CommitteeMembers } from "./collections/committees/committee-members";
import { Committees } from "./collections/committees/committees";
import { Media } from "./collections/media";
import { Pages } from "./collections/pages";
import { Topics } from "./collections/topics";
Expand Down Expand Up @@ -74,7 +76,16 @@ export default buildConfig({
fileSize: 10000000, // 10MB, written in bytes
},
},
collections: [Users, Pages, Media, Topics, BoardMembers, Boards],
collections: [
Users,
Pages,
Media,
Topics,
BoardMembers,
Boards,
CommitteeMembers,
Committees,
],
globals: [Footer, LandingPage, MainNavigation],
localization: {
locales: ["fi", "en"],
Expand Down
56 changes: 56 additions & 0 deletions data/gen/db/committee-members.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
[{
"_id": {
"$oid": "65bbf2b2c081d0fba3620f3c"
},
"guildYear": "2024",
"name": "Joonatan Korpela",
"title": {
"fi": "Digivastaava"
},
"chair": true,
"createdAt": {
"$date": "2024-02-01T19:36:18.175Z"
},
"updatedAt": {
"$date": "2024-02-01T19:46:53.528Z"
},
"__v": 0,
"telegramUsername": "@joonatan_aatos"
},
{
"_id": {
"$oid": "65bbf2cec081d0fba3620f40"
},
"guildYear": "2024",
"name": "Mikael Siidorow",
"title": {
"fi": "Diginatiivi"
},
"chair": false,
"createdAt": {
"$date": "2024-02-01T19:36:46.361Z"
},
"updatedAt": {
"$date": "2024-02-01T19:36:46.361Z"
},
"__v": 0
},
{
"_id": {
"$oid": "65bbf2f1c081d0fba3620f44"
},
"guildYear": "2024",
"name": "Petrus Asikainen",
"title": {
"fi": "Lead Purkka Coder"
},
"chair": false,
"createdAt": {
"$date": "2024-02-01T19:37:21.184Z"
},
"updatedAt": {
"$date": "2024-02-01T19:37:21.184Z"
},
"__v": 0
}]

Loading

0 comments on commit a51a118

Please sign in to comment.