Skip to content

Commit

Permalink
fix: remove required on description and url in partner collection and…
Browse files Browse the repository at this point in the history
… add required url in offer kind online
  • Loading branch information
HoreKk committed Feb 29, 2024
1 parent 188b30f commit 1cf235f
Show file tree
Hide file tree
Showing 6 changed files with 2,196 additions and 151 deletions.
2 changes: 1 addition & 1 deletion webapp/src/pages/dashboard/offer/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export default function OfferPage() {
} = useDisclosure({
onOpen: () => {
const timeoutId = setTimeout(() => {
window.open(offer?.partner.url, "_blank");
window.open(offer?.url as string, "_blank");
onCloseExternalLink();
}, 1000);
setTimeoutIdExternalLink(timeoutId);
Expand Down
305 changes: 159 additions & 146 deletions webapp/src/payload/collections/Offer.ts
Original file line number Diff line number Diff line change
@@ -1,155 +1,168 @@
import { type CollectionConfig } from "payload/types";
import {
CustomSelectTermsOfUse,
getItemsTermsOfUse,
CustomSelectTermsOfUse,
getItemsTermsOfUse,
} from "../components/CustomSelectField";
import { QuickAccess } from "../payload-types";

export const Offers: CollectionConfig = {
slug: "offers",
labels: {
singular: "Offre",
plural: "Offres",
},
admin: {
useAsTitle: "title",
},
fields: [
{
name: "title",
type: "text",
label: "Titre",
required: true,
},
{
name: "partner",
type: "relationship",
label: "Partenaire",
relationTo: "partners",
hasMany: false,
required: true,
},
{
name: "category",
type: "relationship",
label: "Catégorie",
relationTo: "categories",
hasMany: false,
required: true,
},
{
name: "validityFrom",
type: "date",
label: "Offre valide à partir du",
},
{
name: "validityTo",
type: "date",
label: "Offre valide jusqu'au (inclus)",
required: true,
},
{
type: "select",
name: "kind",
label: "Type",
required: true,
defaultValue: 'voucher',
options: [
{ label: "[En magasin] Bon d'achat + pass CJE", value: "voucher" },
{ label: "[En magasin] Pass CJE", value: "voucher_pass" },
{ label: "[En ligne] Code de réduction", value: "code" },
{ label: "[En ligne] Espace de réduction", value: "code_space" },
],
},
{
name: "nbOfEligibleStores",
type: "number",
label: "Nombre de magasins éligibles",
admin: {
condition: (_, siblingData) => !!siblingData.kind && siblingData.kind.startsWith("voucher"),
},
defaultValue: 1,
},
{
name: "imageOfEligibleStores",
type: "upload",
label: "Image des magasins éligibles",
relationTo: "media",
admin: {
condition: (_, siblingData) => !!siblingData.kind && siblingData.kind.startsWith("voucher"),
},
},
{
name: "linkOfEligibleStores",
type: "text",
label: "Lien des magasins éligibles",
admin: {
condition: (_, siblingData) => !!siblingData.kind && siblingData.kind.startsWith("voucher"),
},
},
{
name: "termsOfUse",
type: "array",
label: "Comment ça marche ?",
labels: {
singular: "Étape",
plural: "Étapes",
},
defaultValue: [],
fields: [
{
name: "slug",
type: "text",
label: "Texte",
admin: {
components: {
Field: CustomSelectTermsOfUse,
},
},
},
{
name: "isHighlighted",
type: "checkbox",
label: "Mettre en avant ?",
},
],
},
{
name: "conditions",
type: "array",
label: "Conditions",
labels: {
singular: "Condition",
plural: "Conditions",
},
fields: [
{
name: "text",
type: "text",
label: "Texte",
required: true,
},
],
},
],
hooks: {
afterDelete: [
async ({ req, id }) => {
// Delete on cascade the related quickAccess item
let currentQuickAccess: QuickAccess = await req.payload.findGlobal({
slug: "quickAccess",
depth: 0,
});
slug: "offers",
labels: {
singular: "Offre",
plural: "Offres",
},
admin: {
useAsTitle: "title",
},
fields: [
{
name: "title",
type: "text",
label: "Titre",
required: true,
},
{
name: "partner",
type: "relationship",
label: "Partenaire",
relationTo: "partners",
hasMany: false,
required: true,
},
{
name: "category",
type: "relationship",
label: "Catégorie",
relationTo: "categories",
hasMany: false,
required: true,
},
{
name: "validityFrom",
type: "date",
label: "Offre valide à partir du",
},
{
name: "validityTo",
type: "date",
label: "Offre valide jusqu'au (inclus)",
required: true,
},
{
type: "select",
name: "kind",
label: "Type",
required: true,
defaultValue: "voucher",
options: [
{ label: "[En magasin] Bon d'achat + pass CJE", value: "voucher" },
{ label: "[En magasin] Pass CJE", value: "voucher_pass" },
{ label: "[En ligne] Code de réduction", value: "code" },
{ label: "[En ligne] Espace de réduction", value: "code_space" },
],
},
{
name: "url",
type: "text",
label: "Lien de redirection de l'offre",
admin: {
condition: (_, siblingData) =>
!!siblingData.kind && siblingData.kind.startsWith("code"),
},
required: true,
},
{
name: "nbOfEligibleStores",
type: "number",
label: "Nombre de magasins éligibles",
admin: {
condition: (_, siblingData) =>
!!siblingData.kind && siblingData.kind.startsWith("voucher"),
},
defaultValue: 1,
},
{
name: "imageOfEligibleStores",
type: "upload",
label: "Image des magasins éligibles",
relationTo: "media",
admin: {
condition: (_, siblingData) =>
!!siblingData.kind && siblingData.kind.startsWith("voucher"),
},
},
{
name: "linkOfEligibleStores",
type: "text",
label: "Lien des magasins éligibles",
admin: {
condition: (_, siblingData) =>
!!siblingData.kind && siblingData.kind.startsWith("voucher"),
},
},
{
name: "termsOfUse",
type: "array",
label: "Comment ça marche ?",
labels: {
singular: "Étape",
plural: "Étapes",
},
defaultValue: [],
fields: [
{
name: "slug",
type: "text",
label: "Texte",
admin: {
components: {
Field: CustomSelectTermsOfUse,
},
},
},
{
name: "isHighlighted",
type: "checkbox",
label: "Mettre en avant ?",
},
],
},
{
name: "conditions",
type: "array",
label: "Conditions",
labels: {
singular: "Condition",
plural: "Conditions",
},
fields: [
{
name: "text",
type: "text",
label: "Texte",
required: true,
},
],
},
],
hooks: {
afterDelete: [
async ({ req, id }) => {
// Delete on cascade the related quickAccess item
let currentQuickAccess: QuickAccess = await req.payload.findGlobal({
slug: "quickAccess",
depth: 0,
});

currentQuickAccess.items = currentQuickAccess.items?.filter(
(item) => item.offer !== id
);
currentQuickAccess.items = currentQuickAccess.items?.filter(
(item) => item.offer !== id
);

await req.payload.updateGlobal({
slug: "quickAccess",
data: currentQuickAccess,
});
},
],
},
await req.payload.updateGlobal({
slug: "quickAccess",
data: currentQuickAccess,
});
},
],
},
};
2 changes: 0 additions & 2 deletions webapp/src/payload/collections/Partner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,11 @@ export const Partners: CollectionConfig = {
name: "description",
type: "textarea",
label: "Description",
required: true,
},
{
name: "url",
type: "text",
label: "URL",
required: true,
},
{
name: "color",
Expand Down
Loading

0 comments on commit 1cf235f

Please sign in to comment.