Skip to content

Instantly share code, notes, and snippets.

@ainsleyclark
Created February 5, 2025 19:47
Show Gist options
  • Select an option

  • Save ainsleyclark/22d9c42e2ac6812562ef2042fedcdba4 to your computer and use it in GitHub Desktop.

Select an option

Save ainsleyclark/22d9c42e2ac6812562ef2042fedcdba4 to your computer and use it in GitHub Desktop.

Block:

import { Block } from "payload";
import { IdentifierField } from "@/fields/Identifer";

export const ProductsBlock: Block = {
	slug: 'products-block',
	interfaceName: 'BlockProducts',
	labels: {
		singular: 'Product',
		plural: 'Products',
	},
	fields: [
		{
			name: 'items',
			label: 'Products',
			type: 'relationship',
			relationTo: 'products',
			hasMany: true,
			admin: {
				description: 'Select products to display.',
			},
			maxDepth: 20,
		},
		// etc,
	],
}

Products:

import type { CollectionConfig } from 'payload';

export const Products: CollectionConfig = {
	slug: 'products',
	dbName: 'products',
	timestamps: true,
	labels: {
		singular: 'Product',
		plural: 'Products',
	},
	versions: {
		drafts: false,
		maxPerDoc: 10,
	},
	fields: [
		{
			type: 'tabs',
			tabs: [
				{
					label: 'Content',
					fields: [
						{
							name: 'partner',
							label: 'Partner',
							type: 'relationship',
							relationTo: 'partners',
							hasMany: false,
							admin: {
								description: 'Select the partner that this product belongs to.',
							},
							maxDepth: 20,
						},
					],
				},
				
			],
		},
	],
};

Partners:

import type { CollectionConfig } from 'payload';

export const Partners: CollectionConfig = {
	slug: 'partners',
	dbName: 'partners',
	timestamps: true,
	labels: {
		singular: 'Partner',
		plural: 'Partners',
	},
	versions: {
		drafts: false,
		maxPerDoc: 10,
	},
	fields: [
		{
			type: 'tabs',
			tabs: [
				{
					label: 'Content',
					fields: [
						{
							name: 'logo',
							label: 'Logo',
							type: 'upload',
							relationTo: 'media',
							maxDepth: 20,
						},
					],
				},
			],
		},
	],
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment