Removed recorders bio + other fixes

This commit is contained in:
DrMint 2024-04-05 07:41:42 +02:00
parent 609bbe5866
commit a62709e66e
9 changed files with 19 additions and 91 deletions

View File

@ -695,8 +695,10 @@ export const Collectibles = buildVersionedCollectionConfig({
labels: { singular: "Other", plural: "Others" }, labels: { singular: "Other", plural: "Others" },
fields: [ fields: [
translatedFields({ translatedFields({
admin: { className: "no-label" },
name: "translations", name: "translations",
admin: { className: "no-label" },
required: true,
minRows: 1,
fields: [ fields: [
{ {
name: "note", name: "note",

View File

@ -5,9 +5,7 @@ import { QuickFilters } from "../../components/QuickFilters";
import { CollectionGroups, Collections, RecordersRoles } from "../../constants"; import { CollectionGroups, Collections, RecordersRoles } from "../../constants";
import { imageField } from "../../fields/imageField/imageField"; import { imageField } from "../../fields/imageField/imageField";
import { rowField } from "../../fields/rowField/rowField"; import { rowField } from "../../fields/rowField/rowField";
import { translatedFields } from "../../fields/translatedFields/translatedFields";
import { buildCollectionConfig } from "../../utils/collectionConfig"; import { buildCollectionConfig } from "../../utils/collectionConfig";
import { createEditor } from "../../utils/editor";
import { getAllEndpoint } from "./endpoints/getAllEndpoint"; import { getAllEndpoint } from "./endpoints/getAllEndpoint";
import { importFromStrapi } from "./endpoints/importFromStrapi"; import { importFromStrapi } from "./endpoints/importFromStrapi";
import { beforeLoginMustHaveAtLeastOneRole } from "./hooks/beforeLoginMustHaveAtLeastOneRole"; import { beforeLoginMustHaveAtLeastOneRole } from "./hooks/beforeLoginMustHaveAtLeastOneRole";
@ -102,23 +100,6 @@ export const Recorders = buildCollectionConfig({
description: "List of language(s) that this recorder is familiar with", description: "List of language(s) that this recorder is familiar with",
}, },
}, },
translatedFields({
name: fields.biographies,
interfaceName: "RecorderBiographies",
admin: {
// TODO: Reenable when we can use rich text as titles useAsTitle: fields.biography,
description:
"A short personal description about you or your involvement with this project or the franchise",
},
fields: [
{
name: fields.biography,
required: true,
type: "richText",
editor: createEditor({ inlines: true, lists: true, links: true }),
},
],
}),
{ {
name: fields.role, name: fields.role,
type: "select", type: "select",

View File

@ -2,7 +2,7 @@ import payload from "payload";
import { Collections } from "../../../constants"; import { Collections } from "../../../constants";
import { EndpointRecorder } from "../../../sdk"; import { EndpointRecorder } from "../../../sdk";
import { CollectionEndpoint } from "../../../types/payload"; import { CollectionEndpoint } from "../../../types/payload";
import { isPayloadArrayType, isPayloadType, isValidPayloadImage } from "../../../utils/asserts"; import { isPayloadArrayType, isValidPayloadImage } from "../../../utils/asserts";
export const getAllEndpoint: CollectionEndpoint = { export const getAllEndpoint: CollectionEndpoint = {
method: "get", method: "get",
@ -27,16 +27,11 @@ export const getAllEndpoint: CollectionEndpoint = {
).docs; ).docs;
const result: EndpointRecorder[] = recorders.map( const result: EndpointRecorder[] = recorders.map(
({ anonymize, id, username, avatar, biographies, languages }) => ({ ({ anonymize, id, username, avatar, languages }) => ({
id, id,
username: anonymize ? `Recorder#${id.substring(0, 5)}` : username, username: anonymize ? `Recorder#${id.substring(0, 5)}` : username,
...(isValidPayloadImage(avatar) ? { avatar } : {}), ...(isValidPayloadImage(avatar) ? { avatar } : {}),
languages: isPayloadArrayType(languages) ? languages.map(({ id }) => id) : [], languages: isPayloadArrayType(languages) ? languages.map(({ id }) => id) : [],
biographies:
biographies?.map(({ biography, language }) => ({
language: isPayloadType(language) ? language.id : language,
biography,
})) ?? [],
}) })
); );

View File

@ -3,9 +3,8 @@ import { Collections } from "../../../constants";
import { createStrapiImportEndpoint } from "../../../endpoints/createStrapiImportEndpoint"; import { createStrapiImportEndpoint } from "../../../endpoints/createStrapiImportEndpoint";
import { Recorder } from "../../../types/collections"; import { Recorder } from "../../../types/collections";
import { StrapiImage, StrapiLanguage } from "../../../types/strapi"; import { StrapiImage, StrapiLanguage } from "../../../types/strapi";
import { isDefined, isUndefined } from "../../../utils/asserts"; import { isDefined } from "../../../utils/asserts";
import { uploadStrapiImage } from "../../../utils/localApi"; import { uploadStrapiImage } from "../../../utils/localApi";
import { plainTextToLexical } from "../../../utils/string";
type StrapiRecorder = { type StrapiRecorder = {
username: string; username: string;
@ -25,7 +24,7 @@ export const importFromStrapi = createStrapiImportEndpoint<StrapiRecorder>({
}, },
payload: { payload: {
collection: Collections.Recorders, collection: Collections.Recorders,
import: async ({ username, anonymize, anonymous_code, languages, avatar, bio: bios }, user) => { import: async ({ username, anonymize, anonymous_code, languages, avatar }, user) => {
const avatarId = await uploadStrapiImage({ const avatarId = await uploadStrapiImage({
collection: Collections.Images, collection: Collections.Images,
image: avatar, image: avatar,
@ -58,15 +57,6 @@ export const importFromStrapi = createStrapiImportEndpoint<StrapiRecorder>({
anonymize, anonymize,
languages: languages.data?.map((language) => language.attributes.code), languages: languages.data?.map((language) => language.attributes.code),
avatar: avatarId, avatar: avatarId,
biographies: bios?.map(({ language, bio }) => {
if (isUndefined(language.data))
throw new Error("A language is required for a Recorder biography");
if (isUndefined(bio)) throw new Error("A bio is required for a Recorder biography");
return {
language: language.data.attributes.code,
biography: plainTextToLexical(bio),
};
}),
email: `${anonymous_code}@accords-library.com`, email: `${anonymous_code}@accords-library.com`,
password: process.env.RECORDER_DEFAULT_PASSWORD, password: process.env.RECORDER_DEFAULT_PASSWORD,
}, },

View File

@ -14,6 +14,7 @@ export const slugField = ({ admin, ...otherProps }: Props): TextField => ({
type: "text", type: "text",
required: true, required: true,
unique: true, unique: true,
index: true,
validate: validateSlug, validate: validateSlug,
admin: { admin: {
description: description:

View File

@ -17,6 +17,8 @@ import { Recorders } from "./collections/Recorders/Recorders";
import { Tags } from "./collections/Tags/Tags"; import { Tags } from "./collections/Tags/Tags";
import { TagsGroups } from "./collections/TagsGroups/TagsGroups"; import { TagsGroups } from "./collections/TagsGroups/TagsGroups";
import { Videos } from "./collections/Videos/Videos"; import { Videos } from "./collections/Videos/Videos";
import { VideosChannels } from "./collections/VideosChannels/VideosChannels";
import { VideosSubtitles } from "./collections/VideosSubtitles/VideosSubtitles";
import { Wordings } from "./collections/Wordings/Wordings"; import { Wordings } from "./collections/Wordings/Wordings";
import { Icon } from "./components/Icon"; import { Icon } from "./components/Icon";
import { Logo } from "./components/Logo"; import { Logo } from "./components/Logo";
@ -24,13 +26,6 @@ import { Collections } from "./constants";
import { ftpAdapter } from "./plugins/ftpAdapter"; import { ftpAdapter } from "./plugins/ftpAdapter";
import { createEditor } from "./utils/editor"; import { createEditor } from "./utils/editor";
if (!process.env.PAYLOAD_URI) throw new Error("Missing PAYLOAD_URI in .env");
if (!process.env.MONGODB_URI) throw new Error("Missing MONGODB_URI in .env");
if (!process.env.FTP_HOST) throw new Error("Missing FTP_HOST in .env");
if (!process.env.FTP_USER) throw new Error("Missing FTP_USER in .env");
if (!process.env.FTP_PASSWORD) throw new Error("Missing FTP_PASSWORD in .env");
if (!process.env.FTP_BASE_URL) throw new Error("Missing FTP_BASE_URL in .env");
export default buildConfig({ export default buildConfig({
serverURL: process.env.PAYLOAD_URI, serverURL: process.env.PAYLOAD_URI,
admin: { admin: {
@ -54,6 +49,8 @@ export default buildConfig({
Images, Images,
Videos, Videos,
VideosSubtitles,
VideosChannels,
Tags, Tags,
TagsGroups, TagsGroups,
@ -64,7 +61,7 @@ export default buildConfig({
GenericContents, GenericContents,
], ],
db: mongooseAdapter({ db: mongooseAdapter({
url: process.env.MONGODB_URI, url: process.env.MONGODB_URI ?? "",
}), }),
globals: [HomeFolders], globals: [HomeFolders],
telemetry: false, telemetry: false,
@ -79,11 +76,11 @@ export default buildConfig({
collections: { collections: {
[Collections.Videos]: { [Collections.Videos]: {
adapter: ftpAdapter({ adapter: ftpAdapter({
host: process.env.FTP_HOST, host: process.env.FTP_HOST ?? "",
user: process.env.FTP_USER, user: process.env.FTP_USER ?? "",
password: process.env.FTP_PASSWORD, password: process.env.FTP_PASSWORD ?? "",
secure: false, secure: false,
endpoint: process.env.FTP_BASE_URL, endpoint: process.env.FTP_BASE_URL ?? "",
}), }),
disableLocalStorage: true, disableLocalStorage: true,
disablePayloadAccessControl: true, disablePayloadAccessControl: true,

View File

@ -139,10 +139,6 @@ export type EndpointRecorder = {
username: string; username: string;
avatar?: PayloadImage; avatar?: PayloadImage;
languages: string[]; languages: string[];
biographies: {
language: string;
biography: RichTextContent;
}[];
}; };
export type EndpointWording = { export type EndpointWording = {

View File

@ -6,31 +6,6 @@
* and re-run `payload generate:types` to regenerate this file. * and re-run `payload generate:types` to regenerate this file.
*/ */
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "RecorderBiographies".
*/
export type RecorderBiographies =
| {
language: string | Language;
biography: {
root: {
type: string;
children: {
type: string;
version: number;
[k: string]: unknown;
}[];
direction: ("ltr" | "rtl") | null;
format: "left" | "start" | "center" | "right" | "end" | "justify" | "";
indent: number;
version: number;
};
[k: string]: unknown;
};
id?: string | null;
}[]
| null;
/** /**
* This interface was referenced by `Config`'s JSON-Schema * This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "CategoryTranslations". * via the `definition` "CategoryTranslations".
@ -207,7 +182,6 @@ export interface Recorder {
username: string; username: string;
avatar?: string | Image | null; avatar?: string | Image | null;
languages?: (string | Language)[] | null; languages?: (string | Language)[] | null;
biographies?: RecorderBiographies;
role?: ("Admin" | "Recorder" | "Api")[] | null; role?: ("Admin" | "Recorder" | "Api")[] | null;
anonymize: boolean; anonymize: boolean;
email: string; email: string;
@ -426,8 +400,7 @@ export interface Collectible {
blockType: "timeRange"; blockType: "timeRange";
} }
| { | {
translations?: translations: {
| {
language: string | Language; language: string | Language;
note: { note: {
root: { root: {
@ -445,8 +418,7 @@ export interface Collectible {
[k: string]: unknown; [k: string]: unknown;
}; };
id?: string | null; id?: string | null;
}[] }[];
| null;
id?: string | null; id?: string | null;
blockName?: string | null; blockName?: string | null;
blockType: "other"; blockType: "other";

View File

@ -76,18 +76,12 @@ export const handleParentPages = ({
export const handleRecorder = ({ export const handleRecorder = ({
id, id,
biographies,
languages, languages,
username, username,
avatar, avatar,
anonymize, anonymize,
}: Recorder): EndpointRecorder => ({ }: Recorder): EndpointRecorder => ({
id, id,
biographies:
biographies?.map(({ biography, language }) => ({
biography,
language: isPayloadType(language) ? language.id : language,
})) ?? [],
languages: languages?.map((language) => (isPayloadType(language) ? language.id : language)) ?? [], languages: languages?.map((language) => (isPayloadType(language) ? language.id : language)) ?? [],
username: anonymize ? `Recorder#${id.substring(0, 5)}` : username, username: anonymize ? `Recorder#${id.substring(0, 5)}` : username,
...(isValidPayloadImage(avatar) ? { avatar } : {}), ...(isValidPayloadImage(avatar) ? { avatar } : {}),