Skip to content

Commit

Permalink
feat(cms): add products collection to CMS
Browse files Browse the repository at this point in the history
  • Loading branch information
mrzzy committed Jun 2, 2024
1 parent e50aa0d commit 0aaeed0
Show file tree
Hide file tree
Showing 3 changed files with 156 additions and 4 deletions.
126 changes: 126 additions & 0 deletions apps/cms/src/collections/Products.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
import { CollectionConfig } from "payload/types";

/** Products collection stores merch products offerings. */
export const Products: CollectionConfig = {
slug: "products",
admin: {
description: "Merchandise products offerings",
},
fields: [
// by default, payload generates an 'id' field each order automatically
{
name: "name",
type: "text",
required: true,
},
{
name: "colors",
type: "select",
hasMany: true,
options: [
{
label: "Black",
value: "black",
},
{
label: "White",
value: "white",
},
{
label: "Blue",
value: "blue",
},
],
},
{
name: "sizes",
type: "select",
hasMany: true,
options: [
{
label: "Small",
value: "s",
},
{
label: "Medium",
value: "m",
},
{
label: "Large",
value: "l",
},
{
label: "Extra Large",
value: "xl",
},
],
},
{
name: "images",
type: "array",
fields: [
{
name: "url",
type: "text",
required: true,
},
],
},
{
name: "is_available",
label: "Is Available",
type: "checkbox",
},
{
name: "price",
type: "number",
required: true,
admin: {
step: 0.01,
},
min: 0,
},
{
name: "category",
type: "select",
required: true,
options: [
{
label: "Shirt",
value: "shirt",
},
{
label: "Hat",
value: "hat",
},
],
},
{
name: "size_chart",
type: "text",
},
{
name: "stock",
type: "array",
fields: [
{
name: "color",
type: "select",
options: ["black", "white", "blue"],
required: true,
},
{
name: "quantity",
type: "number",
admin: {
step: 1,
},
required: true,
min: 0,
},
],
},
],
};

export default Products;
7 changes: 5 additions & 2 deletions apps/cms/src/payload.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ import MerchOverview from "./admin/views/MerchOverview";
import MerchProducts from "./admin/views/MerchProducts";
import { SCSEIcon, SCSELogo } from "./admin/graphics/Logos";
import BeforeNavLinks from "./admin/components/BeforeNavLinks";
import Order from "./collections/Orders";
import Orders from "./collections/Orders";
import { isUsingCloudStore } from "./utilities/cloud";
import Products from "./collections/Products";

const adapter = createS3Adapter({
config: {
Expand Down Expand Up @@ -70,7 +71,7 @@ export default buildConfig({
return config
},
},
collections: [Categories, Posts, Tags, Users, Media, Order],
collections: [Categories, Posts, Tags, Users, Media, Orders, Products],
csrf: [
// whitelist of domains to allow cookie auth from
process.env.PAYLOAD_PUBLIC_SERVER_URL,
Expand Down Expand Up @@ -100,3 +101,5 @@ export default buildConfig({
]
: [],
});


27 changes: 25 additions & 2 deletions apps/cms/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* tslint:disable */
/* eslint-disable */
/**
* This file was automatically generated by Payload CMS.
* This file was automatically generated by Payload.
* DO NOT MODIFY IT BY HAND. Instead, modify your source Payload config,
* and re-run `payload generate:types` to regenerate this file.
*/
Expand All @@ -23,6 +24,7 @@ export interface Config {
users: User;
media: Media;
orders: Order;
products: Product;
};
globals: {};
}
Expand Down Expand Up @@ -89,7 +91,7 @@ export interface User {
name?: string;
updatedAt: string;
createdAt: string;
email?: string;
email: string;
resetPasswordToken?: string;
resetPasswordExpiration?: string;
salt?: string;
Expand All @@ -109,3 +111,24 @@ export interface Order {
updatedAt: string;
createdAt: string;
}
export interface Product {
id: string;
name: string;
colors?: ('black' | 'white' | 'blue')[];
sizes?: ('s' | 'm' | 'l' | 'xl')[];
images?: {
url: string;
id?: string;
}[];
is_available?: boolean;
price: number;
category: 'shirt' | 'hat';
size_chart?: string;
stock?: {
color: 'black' | 'white' | 'blue';
quantity: number;
id?: string;
}[];
updatedAt: string;
createdAt: string;
}

0 comments on commit 0aaeed0

Please sign in to comment.