-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: remove required on description and url in partner collection and…
… add required url in offer kind online
- Loading branch information
Showing
6 changed files
with
2,196 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}); | ||
}, | ||
], | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.