From baaf5f0c4c08286027311c1f0886585172d47358 Mon Sep 17 00:00:00 2001 From: Jeroen Branje Date: Thu, 29 Feb 2024 10:00:12 +0100 Subject: [PATCH 1/2] feat(envited.ascs.digital): Add offerings to form Signed-off-by: Jeroen Branje --- .../modules/Profile/Profile.schema.ts | 12 +- .../modules/Profile/Profile.tsx | 170 ++++++++++++++---- .../modules/Profile/locales/de_DE.json | 14 +- .../modules/Profile/locales/en_GB.json | 14 +- 4 files changed, 172 insertions(+), 38 deletions(-) diff --git a/apps/envited.ascs.digital/modules/Profile/Profile.schema.ts b/apps/envited.ascs.digital/modules/Profile/Profile.schema.ts index b062a8ef..70428366 100644 --- a/apps/envited.ascs.digital/modules/Profile/Profile.schema.ts +++ b/apps/envited.ascs.digital/modules/Profile/Profile.schema.ts @@ -21,7 +21,17 @@ export const ProfileSchema = z.object({ principalPhone: z.string(), principalEmail: z.string().email().optional().or(z.literal('')), website: z.string().url().optional().or(z.literal('')), - offerings: z.string().array().optional(), + offerings: z + .object({ + name: z.string().max(100), + type: z.string().max(100), + functionalities: z.string().max(100), + supportedTools: z.string().max(200), + supportedStandards: z.string().max(200), + }) + .array() + .max(5) + .optional(), }) export const ValidateProfileForm = ProfileSchema.safeParse diff --git a/apps/envited.ascs.digital/modules/Profile/Profile.tsx b/apps/envited.ascs.digital/modules/Profile/Profile.tsx index 8bab3cc6..b5212c0f 100644 --- a/apps/envited.ascs.digital/modules/Profile/Profile.tsx +++ b/apps/envited.ascs.digital/modules/Profile/Profile.tsx @@ -1,17 +1,10 @@ 'use client' -import { - Card, - Checkboxes, - DragAndDropField, - Heading, - TextField, - TextareaField, -} from '@envited-marketplace/design-system' +import { Card, DragAndDropField, Heading, TextField, TextareaField } from '@envited-marketplace/design-system' import { zodResolver } from '@hookform/resolvers/zod' -import { append, equals, includes, pathOr, prop, propOr, reject } from 'ramda' +import { pathOr, prop, propOr } from 'ramda' import { FC } from 'react' -import { Controller, SubmitHandler, useForm } from 'react-hook-form' +import { Controller, SubmitHandler, useFieldArray, useForm } from 'react-hook-form' import { useTranslation } from '../../common/i18n' import { useNotification } from '../../common/notifications' @@ -24,6 +17,14 @@ interface ProfileProps { memberCategories: any[] } +interface OfferingItem { + name: string + type: string + functionalities: string + supportedTools: string + supportedStandards: string +} + type ProfileInputs = { name: string description: string @@ -40,7 +41,7 @@ type ProfileInputs = { principalPhone: string principalEmail: string website: string - offerings: [] + offerings: OfferingItem[] | [] } export const Profile: FC = ({ profile, memberCategories }) => { @@ -69,16 +70,19 @@ export const Profile: FC = ({ profile, memberCategories }) => { principalPhone: propOr('', 'principalPhone')(profile), principalEmail: propOr('', 'principalEmail')(profile), website: propOr('', 'website')(profile), - offerings: [], + offerings: propOr([], 'offerings')(profile), }, mode: 'onChange', }) - const handleCheckbox = (checkId: string) => { - const { offerings: ids } = getValues() - - return includes(checkId)(ids) ? reject(equals(checkId))(ids) : append(checkId)(ids) - } + const { + fields: offeringFields, + append: appendOffering, + remove: removeOffering, + } = useFieldArray({ + control, + name: 'offerings', + }) const updateProfileAction: SubmitHandler = async data => { try { @@ -124,24 +128,6 @@ export const Profile: FC = ({ profile, memberCategories }) => { /> -
- ( - - )} - /> -
-
= ({ profile, memberCategories }) => {
+
+

+ {t('[Heading] offerings')} +

+

{t('[Description] offerings')}

+ +
+ {offeringFields.map((field, index) => ( +
+
+

+ {t('[Label] offering')} {index + 1} +

+ +
+
+ ( + + )} + /> +
+
+ ( + + )} + /> +
+
+ ( + + )} + /> +
+
+ ( + + )} + /> +
+
+ ( + + )} + /> +
+
+ ))} + {offeringFields.length < 5 && ( + + )} +
+
diff --git a/apps/envited.ascs.digital/modules/Profile/locales/de_DE.json b/apps/envited.ascs.digital/modules/Profile/locales/de_DE.json index 7ce9be9f..f744fc71 100644 --- a/apps/envited.ascs.digital/modules/Profile/locales/de_DE.json +++ b/apps/envited.ascs.digital/modules/Profile/locales/de_DE.json @@ -3,13 +3,22 @@ "[Description] profile": "This information will be displayed publicly so be careful what you share.", "[Heading] principal contact": "Principal Contact Information", "[Description] principal contact": "This contact information will be displayed publicly so be careful what you share.", - "[Heading] sales contact": "Profile", + "[Heading] sales contact": "Sales Contact Information", "[Description] sales contact": "This contact information will be displayed publicly so be careful what you share.", + "[Heading] offerings": "ENVITED data space related offerings", + "[Description] offerings": "Max. 5 entries possible", "[Label] company name": "Company name", "[Label] about": "About", "[Label] about description": "Write a few sentences about the company.", "[Label] logo": "Logo", "[Label] offerings": "Offerings", + "[Label] offering name": "Name of offering", + "[Label] offering type": "Type", + "[Label] offering functionalities": "Functionalities", + "[Label] offering supported tools": "Supported Tools", + "[Description] offering supported tools": "max. 200 characters", + "[Label] offering supported standards": "Supported Standards", + "[Description] offering supported standards": "max. 200 characters", "[Label] website": "Website", "[Label] street": "Street", "[Label] postal code": "Postal code", @@ -18,5 +27,8 @@ "[Label] name": "Name", "[Label] phone": "Phone", "[Label] email": "Email address", + "[Label] offering": "Offering", + "[Button] remove": "Remove offering", + "[Button] add further offerings": "+ add further offerings", "[Button] update profile": "Update profile" } diff --git a/apps/envited.ascs.digital/modules/Profile/locales/en_GB.json b/apps/envited.ascs.digital/modules/Profile/locales/en_GB.json index 7ce9be9f..f744fc71 100644 --- a/apps/envited.ascs.digital/modules/Profile/locales/en_GB.json +++ b/apps/envited.ascs.digital/modules/Profile/locales/en_GB.json @@ -3,13 +3,22 @@ "[Description] profile": "This information will be displayed publicly so be careful what you share.", "[Heading] principal contact": "Principal Contact Information", "[Description] principal contact": "This contact information will be displayed publicly so be careful what you share.", - "[Heading] sales contact": "Profile", + "[Heading] sales contact": "Sales Contact Information", "[Description] sales contact": "This contact information will be displayed publicly so be careful what you share.", + "[Heading] offerings": "ENVITED data space related offerings", + "[Description] offerings": "Max. 5 entries possible", "[Label] company name": "Company name", "[Label] about": "About", "[Label] about description": "Write a few sentences about the company.", "[Label] logo": "Logo", "[Label] offerings": "Offerings", + "[Label] offering name": "Name of offering", + "[Label] offering type": "Type", + "[Label] offering functionalities": "Functionalities", + "[Label] offering supported tools": "Supported Tools", + "[Description] offering supported tools": "max. 200 characters", + "[Label] offering supported standards": "Supported Standards", + "[Description] offering supported standards": "max. 200 characters", "[Label] website": "Website", "[Label] street": "Street", "[Label] postal code": "Postal code", @@ -18,5 +27,8 @@ "[Label] name": "Name", "[Label] phone": "Phone", "[Label] email": "Email address", + "[Label] offering": "Offering", + "[Button] remove": "Remove offering", + "[Button] add further offerings": "+ add further offerings", "[Button] update profile": "Update profile" } From 514e3c8b2ea5e5e728b11cd03392aeebb20a0d1f Mon Sep 17 00:00:00 2001 From: Jeroen Branje Date: Thu, 29 Feb 2024 11:51:59 +0100 Subject: [PATCH 2/2] feat(envited.ascs.digital): Add ramda mapIndexed Signed-off-by: Jeroen Branje --- apps/envited.ascs.digital/common/utils/index.ts | 1 + apps/envited.ascs.digital/common/utils/utils.ts | 4 +++- apps/envited.ascs.digital/modules/Profile/Profile.tsx | 5 +++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/apps/envited.ascs.digital/common/utils/index.ts b/apps/envited.ascs.digital/common/utils/index.ts index 60088598..4aa099d8 100644 --- a/apps/envited.ascs.digital/common/utils/index.ts +++ b/apps/envited.ascs.digital/common/utils/index.ts @@ -16,4 +16,5 @@ export { extractTypeFromCredential, slugify, createRandomString, + mapIndexed, } from './utils' diff --git a/apps/envited.ascs.digital/common/utils/utils.ts b/apps/envited.ascs.digital/common/utils/utils.ts index ddb32f80..5693e3f0 100644 --- a/apps/envited.ascs.digital/common/utils/utils.ts +++ b/apps/envited.ascs.digital/common/utils/utils.ts @@ -1,4 +1,4 @@ -import { pathOr, times } from 'ramda' +import { addIndex, map, pathOr, times } from 'ramda' export const extractIdFromCredential = pathOr('', ['credentialSubject', 'id']) @@ -21,3 +21,5 @@ export const createRandomString = (length: number) => { return result } + +export const mapIndexed = addIndex(map) diff --git a/apps/envited.ascs.digital/modules/Profile/Profile.tsx b/apps/envited.ascs.digital/modules/Profile/Profile.tsx index b5212c0f..9025bb68 100644 --- a/apps/envited.ascs.digital/modules/Profile/Profile.tsx +++ b/apps/envited.ascs.digital/modules/Profile/Profile.tsx @@ -9,6 +9,7 @@ import { Controller, SubmitHandler, useFieldArray, useForm } from 'react-hook-fo import { useTranslation } from '../../common/i18n' import { useNotification } from '../../common/notifications' import { File, Profile as ProfileType } from '../../common/types' +import { mapIndexed } from '../../common/utils' import { updateProfileForm } from './Profile.actions' import { ProfileSchema } from './Profile.schema' @@ -362,7 +363,7 @@ export const Profile: FC = ({ profile, memberCategories }) => {

{t('[Description] offerings')}

- {offeringFields.map((field, index) => ( + {mapIndexed((field: any, index: number) => (

@@ -449,7 +450,7 @@ export const Profile: FC = ({ profile, memberCategories }) => { />

- ))} + ))(offeringFields)} {offeringFields.length < 5 && (