Skip to content

Commit

Permalink
refactor(cms): change categories, colors, sizes to has many text fields
Browse files Browse the repository at this point in the history
  • Loading branch information
mrzzy committed Sep 8, 2024
1 parent bb7e6df commit e999af3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 51 deletions.
61 changes: 14 additions & 47 deletions apps/cms/src/collections/Products.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export const Products: CollectionConfig = {
slug: "products",
admin: {
description: "Merchandise products offerings",
defaultColumns: ["name", "category", "price", "is_available"],
},
fields: [
// by default, payload generates an 'id' field each order automatically
Expand All @@ -15,45 +16,14 @@ export const Products: CollectionConfig = {
},
{
name: "colors",
type: "select",
type: "text",
required: true,
hasMany: true,
options: [
{
label: "Black",
value: "black",
},
{
label: "White",
value: "white",
},
{
label: "Blue",
value: "blue",
},
],
},
{
name: "sizes",
type: "select",
type: "text",
hasMany: true,
options: [
{
label: "Small",
value: "s",
},
{
label: "Medium",
value: "m",
},
{
label: "Large",
value: "l",
},
{
label: "Extra Large",
value: "xl",
},
],
},
{
name: "images",
Expand Down Expand Up @@ -82,21 +52,14 @@ export const Products: CollectionConfig = {
},
{
name: "category",
type: "select",
type: "text",
required: true,
options: [
{
label: "Shirt",
value: "shirt",
},
{
label: "Hat",
value: "hat",
},
],
hasMany: true,
minRows: 1,
},
{
name: "size_chart",
label: "Size Chart",
type: "text",
},
{
Expand All @@ -105,8 +68,12 @@ export const Products: CollectionConfig = {
fields: [
{
name: "color",
type: "select",
options: ["black", "white", "blue"],
type: "text",
required: true,
},
{
name: "size",
type: "text",
required: true,
},
{
Expand Down
9 changes: 5 additions & 4 deletions apps/cms/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ export interface Order {
export interface Product {
id: string;
name: string;
colors?: ('black' | 'white' | 'blue')[] | null;
sizes?: ('s' | 'm' | 'l' | 'xl')[] | null;
colors: string[];
sizes?: string[] | null;
images?:
| {
url: string;
Expand All @@ -170,11 +170,12 @@ export interface Product {
| null;
is_available?: boolean | null;
price: number;
category: 'shirt' | 'hat';
category: string[];
size_chart?: string | null;
stock?:
| {
color: 'black' | 'white' | 'blue';
color: string;
size: string;
quantity: number;
id?: string | null;
}[]
Expand Down

0 comments on commit e999af3

Please sign in to comment.