Skip to content

Commit

Permalink
fix: payload custom components for RowLabels and CustomSelect migrate
Browse files Browse the repository at this point in the history
  • Loading branch information
HoreKk committed Nov 20, 2024
1 parent 3cb3337 commit 59a4c3c
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 17 deletions.
2 changes: 1 addition & 1 deletion webapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"private": true,
"type": "module",
"scripts": {
"dev": "next dev",
"dev": "next dev --turbo",
"build": "next build",
"start": "next start",
"seed:dev": "PAYLOAD_DROP_DATABASE=true tsx ./src/payload/seed/index.ts",
Expand Down
8 changes: 6 additions & 2 deletions webapp/src/app/(payload)/admin/importMap.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@

import { CustomSelectKind as CustomSelectKind_9dcf769af922a51107998c78ff4db18a } from '~/payload/components/CustomSelectKind'
import { OfferRowLabel as OfferRowLabel_96c0a6bbcec834bdb17d8993615131f7 } from '~/payload/components/RowLabels'
import { OrderRowLabel as OrderRowLabel_96c0a6bbcec834bdb17d8993615131f7 } from '~/payload/components/RowLabels'

export const importMap = {

"~/payload/components/CustomSelectKind#CustomSelectKind": CustomSelectKind_9dcf769af922a51107998c78ff4db18a,
"~/payload/components/RowLabels#OfferRowLabel": OfferRowLabel_96c0a6bbcec834bdb17d8993615131f7,
"~/payload/components/RowLabels#OrderRowLabel": OrderRowLabel_96c0a6bbcec834bdb17d8993615131f7
}
24 changes: 16 additions & 8 deletions webapp/src/payload/collections/Offer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,10 @@ export const Offers: CollectionConfig = {
admin: {
position: "sidebar",
components: {
// Field: CustomSelectKind,
Field: {
path: "~/payload/components/CustomSelectKind",
exportName: "CustomSelectKind",
},
},
},
},
Expand Down Expand Up @@ -246,7 +249,10 @@ export const Offers: CollectionConfig = {
label: "Texte",
admin: {
components: {
// Field: CustomSelectTermsOfUse,
Field: {
path: "~/payload/components/CustomSelectTermsOfUse",
exportName: "CustomSelectTermsOfUse",
},
},
},
},
Expand Down Expand Up @@ -293,7 +299,10 @@ export const Offers: CollectionConfig = {
label: "Texte",
admin: {
components: {
// Field: CustomSelectConditionBlocks,
Field: {
path: "~/payload/components/CustomSelectConditionBlocks",
exportName: "CustomSelectConditionBlocks",
},
},
},
},
Expand All @@ -317,11 +326,10 @@ export const Offers: CollectionConfig = {
!!siblingData.source && siblingData.source === "obiz",
initCollapsed: true,
components: {
// RowLabel: ({ data, index }: any) => {
// return data
// ? `${data.available ? "🟢" : "🔴"} ${data.name}`
// : `Article ${String(index).padStart(2, "0")}`;
// },
RowLabel: {
path: "~/payload/components/RowLabels",
exportName: "OfferRowLabel",
},
},
},
fields: [
Expand Down
7 changes: 4 additions & 3 deletions webapp/src/payload/collections/Order.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,10 @@ export const Orders: CollectionConfig = {
label: "Panier",
admin: {
components: {
// RowLabel: ({ data }: any) => {
// return `${data.article_reference} (x${data.article_quantity})`;
// },
RowLabel: {
path: "~/payload/components/RowLabels",
exportName: "OrderRowLabel",
},
},
},
fields: [
Expand Down
5 changes: 4 additions & 1 deletion webapp/src/payload/components/CustomSelectBlocksOfUse.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ export const CustomSelectConditionBlocks: React.FC<{ path: string }> = ({
name={path}
options={options}
value={value}
onChange={(e) => setValue(e.value)}
onChange={(e) => {
const option = e as { label: string; value: string };
setValue(option.value);
}}
/>
</div>
);
Expand Down
7 changes: 6 additions & 1 deletion webapp/src/payload/components/CustomSelectKind.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"use client";

import { SelectInput, useField, useFormFields } from "@payloadcms/ui";
import React from "react";
import { Offer } from "../payload-types";
Expand Down Expand Up @@ -44,7 +46,10 @@ export const CustomSelectKind: React.FC<{ path: string }> = ({ path }) => {
name={path}
options={options}
value={value}
onChange={(e) => setValue(e.value)}
onChange={(e) => {
const option = e as { label: string; value: string };
setValue(option.value);
}}
/>
</div>
);
Expand Down
7 changes: 6 additions & 1 deletion webapp/src/payload/components/CustomSelectTermsOfUse.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"use client";

import { SelectInput, useField, useFormFields } from "@payloadcms/ui";
import { Offer } from "../payload-types";
import React from "react";
Expand Down Expand Up @@ -140,7 +142,10 @@ export const CustomSelectTermsOfUse: React.FC<{ path: string }> = ({
name={path}
options={options}
value={value}
onChange={(e) => setValue(e.value)}
onChange={(e) => {
const option = e as { label: string; value: string };
setValue(option.value);
}}
/>
</div>
);
Expand Down
25 changes: 25 additions & 0 deletions webapp/src/payload/components/RowLabels.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"use client";

import { useRowLabel } from "@payloadcms/ui";

export const OfferRowLabel = () => {
const { data, rowNumber } = useRowLabel<{
name?: string;
available?: boolean;
}>();

return (
<div>{`${data.available ? "🟢" : "🔴"} ${(rowNumber ?? 0) + 1}. ${data.name ?? ""}`}</div>
);
};

export const OrderRowLabel = () => {
const { data } = useRowLabel<{
article_reference?: string;
article_quantity?: number;
}>();

return (
<div>{`${data.article_reference ?? ""} (x${data.article_quantity ?? 0})`}</div>
);
};

0 comments on commit 59a4c3c

Please sign in to comment.