Skip to content

Commit

Permalink
add boards and board members collections
Browse files Browse the repository at this point in the history
  • Loading branch information
MikaelSiidorow committed Jan 18, 2024
1 parent a2ccaa9 commit 4e58094
Show file tree
Hide file tree
Showing 10 changed files with 3,093 additions and 1,012 deletions.
50 changes: 50 additions & 0 deletions apps/cms/src/collections/board/board-members.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import type { CollectionConfig } from "payload/types";
import { signedIn } from "../../access/signed-in";
import { guildYearField } from "../../fields/guild-year";

export const BoardMembers: CollectionConfig = {
slug: "board-members",
defaultSort: "-guildYear",
admin: {
useAsTitle: "name",
defaultColumns: ["guildYear", "photo", "name", "title"],
},
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: "email",
type: "email",
required: true,
},
{
name: "telegram",
type: "text",
required: true,
},
],
};
57 changes: 57 additions & 0 deletions apps/cms/src/collections/board/boards.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import type { Board } 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<Board> = ({ data }) => ({
guildYear: {
equals: data.year,
},
});

export const Boards: CollectionConfig = {
slug: "boards",
defaultSort: "-year",
admin: {
useAsTitle: "year",
defaultColumns: ["year", "groupPhoto"],
},
access: {
read: () => true,
create: signedIn,
update: signedIn,
delete: signedIn,
},
fields: [
guildYearField({
name: "year",
required: true,
}),
{
name: "description",
maxLength: 360,
type: "textarea",
localized: true,
required: true,
},
{
name: "groupPhoto",
type: "relationship",
relationTo: "media",
},
{
name: "boardMembers",
type: "array",
required: true,
minRows: 3,
fields: [
{
name: "boardMember",
type: "relationship",
relationTo: "board-members",
filterOptions: filterCurrentYear,
},
],
},
],
};
17 changes: 17 additions & 0 deletions apps/cms/src/fields/guild-year.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import type { Field, FieldBase } from "payload/dist/fields/config/types";

const currentYear = new Date().getFullYear();
const foundedYear = 1986;

export const guildYearField = (
base: Omit<FieldBase, "name"> & { name?: string } = {},
): Field => ({
name: "guildYear",
hasMany: false,
...base,
type: "select",
options: Array.from(
{ length: currentYear - foundedYear + 1 },
(_, i) => `${currentYear - i}`,
),
});
6 changes: 4 additions & 2 deletions apps/cms/src/payload.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import path from "path";
import { webpackBundler } from "@payloadcms/bundler-webpack";
import { mongooseAdapter } from "@payloadcms/db-mongodb";
import { cloudStorage } from "@payloadcms/plugin-cloud-storage";
import { azureBlobStorageAdapter } from "@payloadcms/plugin-cloud-storage/azure";
import {
AlignFeature,
BlockQuoteFeature,
Expand All @@ -24,7 +25,8 @@ import {
import type { Config } from "@tietokilta/cms-types/payload";
import { oAuthPlugin } from "payload-plugin-oauth";
import { buildConfig } from "payload/config";
import { azureBlobStorageAdapter } from "@payloadcms/plugin-cloud-storage/azure";
import { BoardMembers } from "./collections/board/board-members";
import { Boards } from "./collections/board/boards";
import { Media } from "./collections/media";
import { Pages } from "./collections/pages";
import { Topics } from "./collections/topics";
Expand Down Expand Up @@ -66,12 +68,12 @@ export default buildConfig({
}
: false,
},
collections: [Users, Pages, Media, Topics],
upload: {
limits: {
fileSize: 5000000, // 5MB, written in bytes
},
},
collections: [Users, Pages, Media, Topics, BoardMembers, Boards],
globals: [Footer, LandingPage, MainNavigation],
localization: {
locales: ["fi", "en"],
Expand Down
81 changes: 81 additions & 0 deletions data/gen/db/board-members.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
[{
"_id": {
"$oid": "65a6abbbc653ae138bb3c085"
},
"guildYear": "2024",
"name": "Mikael Siidorow",
"title": {
"fi": "Puheenjohtaja",
"en": "Chair"
},
"email": "[email protected]",
"telegram": "Tietokila",
"createdAt": {
"$date": "2024-01-16T16:15:55.83Z"
},
"updatedAt": {
"$date": "2024-01-16T16:16:35.564Z"
},
"__v": 0
},
{
"_id": {
"$oid": "65a6ace2990f05954dcac743"
},
"guildYear": "2024",
"name": "Lauri Lappalainen",
"title": {
"fi": "Varapuheenjohtaja",
"en": "Vice Chair"
},
"email": "[email protected]",
"telegram": "labbbis",
"createdAt": {
"$date": "2024-01-16T16:20:50.659Z"
},
"updatedAt": {
"$date": "2024-01-16T16:21:34.767Z"
},
"__v": 0
},
{
"_id": {
"$oid": "65a6ad15990f05954dcac75f"
},
"guildYear": "2024",
"name": "Samu \"Chef\" Paakkari",
"title": {
"fi": "Rahastonhoitaja",
"en": "Treasurer"
},
"email": "[email protected]",
"telegram": "chefz",
"createdAt": {
"$date": "2024-01-16T16:21:41.475Z"
},
"updatedAt": {
"$date": "2024-01-16T16:22:08.083Z"
},
"__v": 0
},
{
"_id": {
"$oid": "65a6b338848d0618d686b114"
},
"guildYear": "2023",
"name": "Joonas Sorvari",
"title": {
"fi": "Puheenjohtaja",
"en": "Chair"
},
"email": "[email protected]",
"telegram": "Tietokila",
"createdAt": {
"$date": "2024-01-16T16:47:52.452Z"
},
"updatedAt": {
"$date": "2024-01-16T16:47:57.851Z"
},
"__v": 0
}]

31 changes: 31 additions & 0 deletions data/gen/db/boards.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
[{
"_id": {
"$oid": "65a6b375848d0618d686b139"
},
"year": "2024",
"description": {
"en": "Tällä sivulla on esitelty killan hallituksen jäsenet vuodelle 2024 yhteystietoineen.\nMikäli haluat ottaa yhteyttä koko hallitukseen, voit lähettää sähköpostia osoitteeseen hallitus (at) tietokilta.fi."
},
"boardMembers": [
{
"boardMember": "65a6abbbc653ae138bb3c085",
"id": "65a6b3753aabf6ee79336ffe"
},
{
"boardMember": "65a6ad15990f05954dcac75f",
"id": "65a6b3753aabf6ee79336fff"
},
{
"boardMember": "65a6ace2990f05954dcac743",
"id": "65a6b3753aabf6ee79337000"
}
],
"createdAt": {
"$date": "2024-01-16T16:48:53.956Z"
},
"updatedAt": {
"$date": "2024-01-16T16:48:53.956Z"
},
"__v": 0
}]

Loading

0 comments on commit 4e58094

Please sign in to comment.