The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
v1.6.0 — Partners: let partners set the regions they serve on My Profile (#23605)
Rashad Karanouh4f429a39762a
diff --git a/packages/twenty-apps/internal/twenty-partners/package.json b/packages/twenty-apps/internal/twenty-partners/package.jsonindex baaef5531a9..b24c7c83f4f 100644--- a/packages/twenty-apps/internal/twenty-partners/package.json+++ b/packages/twenty-apps/internal/twenty-partners/package.json@@ -1,6 +1,6 @@{"name": "twenty-partners",- "version": "1.5.1",+ "version": "1.6.0","license": "MIT","engines": {"node": "^24.5.0",diff --git a/packages/twenty-apps/internal/twenty-partners/src/modules/partner/self-service/__tests__/save-my-partner-profile.integration-test.ts b/packages/twenty-apps/internal/twenty-partners/src/modules/partner/self-service/__tests__/save-my-partner-profile.integration-test.tsindex 1aeff132f81..f1fe9ab4b82 100644--- a/packages/twenty-apps/internal/twenty-partners/src/modules/partner/self-service/__tests__/save-my-partner-profile.integration-test.ts+++ b/packages/twenty-apps/internal/twenty-partners/src/modules/partner/self-service/__tests__/save-my-partner-profile.integration-test.ts@@ -207,7 +207,7 @@ describe('save-my-partner-profile', () => {expect(partner.hourlyRate).toEqual({ amountMicros: 150000000, currencyCode: 'USD' });expect(partner.website?.primaryLinkUrl).toBe('https://updated.example.com');- // Admin-only fields are never in the editable schema, so they must survive untouched.+ // Fields absent from the body must survive untouched.expect(partner.region).toEqual(['EUROPE']);expect(partner.deploymentExpertise).toEqual(['CLOUD']);});diff --git a/packages/twenty-apps/internal/twenty-partners/src/modules/partner/self-service/constants/my-profile.constants.ts b/packages/twenty-apps/internal/twenty-partners/src/modules/partner/self-service/constants/my-profile.constants.tsindex 38141c903d2..4914df3f470 100644--- a/packages/twenty-apps/internal/twenty-partners/src/modules/partner/self-service/constants/my-profile.constants.ts+++ b/packages/twenty-apps/internal/twenty-partners/src/modules/partner/self-service/constants/my-profile.constants.ts@@ -15,6 +15,7 @@ export type ProfileOptions = {partnerScope: SelectOption[];typeOfTeam: SelectOption[];availability: SelectOption[];+ region: SelectOption[];};// These mirror the option lists declared on the Partner object (partner.object.ts).@@ -36,6 +37,14 @@ export const PROFILE_OPTIONS: ProfileOptions = {{ value: 'AVAILABLE', label: 'Available' },{ value: 'UNAVAILABLE', label: 'Unavailable' },],+ region: [+ { value: 'EUROPE', label: 'Europe' },+ { value: 'US', label: 'US' },+ { value: 'LATAM', label: 'LATAM' },+ { value: 'MENA', label: 'MENA' },+ { value: 'APAC', label: 'APAC' },+ { value: 'AFRICA', label: 'Africa' },+ ],languagesSpoken: [{ value: 'ENGLISH', label: 'English' },{ value: 'FRENCH', label: 'French' },diff --git a/packages/twenty-apps/internal/twenty-partners/src/modules/partner/self-service/front-components/my-profile.front-component.tsx b/packages/twenty-apps/internal/twenty-partners/src/modules/partner/self-service/front-components/my-profile.front-component.tsxindex 11703f88926..8df99301991 100644--- a/packages/twenty-apps/internal/twenty-partners/src/modules/partner/self-service/front-components/my-profile.front-component.tsx+++ b/packages/twenty-apps/internal/twenty-partners/src/modules/partner/self-service/front-components/my-profile.front-component.tsx@@ -17,61 +17,13 @@ import {TagInput,TextInput,UrlInput,- type SelectOption,} from './my-profile/form-fields';--type Currency = { amountMicros: number | null; currencyCode: string | null } | null;--type ProfilePayload = {- id: string;- name: string | null;- profilePictureUrl: string | null;- introduction: string | null;- city: string | null;- country: string | null;- languagesSpoken: string[] | null;- partnerScope: string[] | null;- skills: string[] | null;- typeOfTeam: string | null;- availability: string | null;- hourlyRate: Currency;- projectBudgetMin: Currency;- website: string | null;- linkedin: string | null;- calendarLink: string | null;-};--type ProfileOptions = {- country: SelectOption[];- languagesSpoken: SelectOption[];- partnerScope: SelectOption[];- typeOfTeam: SelectOption[];- availability: SelectOption[];-};--type LoadResult =- | { ok: true; profile: ProfilePayload; options: ProfileOptions }- | { ok: false; reason: string };-type SaveResult = { ok: true } | { ok: false; reason: string };--type MoneyField = { amount: number | null; currencyCode: string };--type ProfileForm = {- name: string;- introduction: string;- availability: string;- typeOfTeam: string;- hourlyRate: MoneyField;- projectBudgetMin: MoneyField;- partnerScope: string[];- skills: string[];- languagesSpoken: string[];- country: string;- city: string;- website: string;- linkedin: string;- calendarLink: string;-};+import { toProfileForm, toSaveBody, type ProfileForm } from './my-profile/profile-form';+import type {+ MyPartnerProfileResult,+ ProfileOptions,+ SaveResult,+} from './my-profile/types';const SKILL_SUGGESTIONS = ['Migrations',@@ -90,53 +42,6 @@ const SKILL_SUGGESTIONS = ['Custom development',];-const MICROS = 1_000_000;--const toMoneyField = (value: Currency): MoneyField => ({- amount: value?.amountMicros != null ? value.amountMicros / MICROS : null,- currencyCode: value?.currencyCode ?? 'USD',-});--const toProfileForm = (profile: ProfilePayload): ProfileForm => ({- name: profile.name ?? '',- introduction: profile.introduction ?? '',- availability: profile.availability ?? '',- typeOfTeam: profile.typeOfTeam ?? '',- hourlyRate: toMoneyField(profile.hourlyRate),- projectBudgetMin: toMoneyField(profile.projectBudgetMin),- partnerScope: profile.partnerScope ?? [],- skills: profile.skills ?? [],- languagesSpoken: profile.languagesSpoken ?? [],- country: profile.country ?? '',- city: profile.city ?? '',- website: profile.website ?? '',- linkedin: profile.linkedin ?? '',- calendarLink: profile.calendarLink ?? '',-});--const toMicros = (money: MoneyField) =>- money.amount == null- ? null- : { amountMicros: Math.round(money.amount * MICROS), currencyCode: money.currencyCode || 'USD' };--// Enum/country selectors send null (not '') when reset to blank so the field clears.-const toSaveBody = (form: ProfileForm): Record<string, unknown> => ({- name: form.name,- introduction: form.introduction,- city: form.city,- languagesSpoken: form.languagesSpoken,- partnerScope: form.partnerScope,- skills: form.skills,- website: form.website,- linkedin: form.linkedin,- calendarLink: form.calendarLink,- hourlyRate: toMicros(form.hourlyRate),- projectBudgetMin: toMicros(form.projectBudgetMin),- availability: form.availability === '' ? null : form.availability,- typeOfTeam: form.typeOfTeam === '' ? null : form.typeOfTeam,- country: form.country === '' ? null : form.country,-});-const styles = {root: {display: 'flex',@@ -213,7 +118,7 @@ const MyProfile = () => {const load = useCallback(async () => {setLoading(true);try {- const res = (await callAppRoute('/my-partner-profile', {})) as LoadResult;+ const res = (await callAppRoute('/my-partner-profile', {})) as MyPartnerProfileResult;if (res.ok) {setForm(toProfileForm(res.profile));setOptions(res.options);@@ -370,6 +275,13 @@ const MyProfile = () => {</Field></div></div>+ <Field label="Regions served">+ <ChipMultiSelect+ value={form.region}+ options={options.region}+ onChange={(value) => set('region', value)}+ />+ </Field></Section><Section title="Links">diff --git a/packages/twenty-apps/internal/twenty-partners/src/modules/partner/self-service/front-components/my-profile/profile-form.test.ts b/packages/twenty-apps/internal/twenty-partners/src/modules/partner/self-service/front-components/my-profile/profile-form.test.tsnew file mode 100644index 00000000000..732bc9f114c--- /dev/null+++ b/packages/twenty-apps/internal/twenty-partners/src/modules/partner/self-service/front-components/my-profile/profile-form.test.ts@@ -0,0 +1,59 @@+import { describe, expect, it } from 'vitest';++import { toProfileForm, toSaveBody, type ProfilePayload } from './profile-form';++const emptyPayload: ProfilePayload = {+ id: 'partner-1',+ name: 'Nine Dots Ventures',+ profilePictureUrl: null,+ introduction: null,+ city: null,+ country: null,+ languagesSpoken: null,+ region: null,+ partnerScope: null,+ skills: null,+ typeOfTeam: null,+ availability: null,+ hourlyRate: null,+ projectBudgetMin: null,+ website: null,+ linkedin: null,+ calendarLink: null,+};++describe('toProfileForm', () => {+ it('carries region through', () => {+ expect(toProfileForm({ ...emptyPayload, region: ['EUROPE', 'MENA'] }).region).toEqual([+ 'EUROPE',+ 'MENA',+ ]);+ });++ it('defaults a null region to an empty array', () => {+ expect(toProfileForm(emptyPayload).region).toEqual([]);+ });+});++describe('toSaveBody', () => {+ it('sends region as an array', () => {+ const body = toSaveBody({ ...toProfileForm(emptyPayload), region: ['APAC'] });+ expect(body.region).toEqual(['APAC']);+ });++ it('sends an empty region array when nothing is selected', () => {+ expect(toSaveBody(toProfileForm(emptyPayload)).region).toEqual([]);+ });++ it('sends null for a blank country, not an empty string', () => {+ expect(toSaveBody(toProfileForm(emptyPayload)).country).toBeNull();+ });++ it('converts a money field to micros', () => {+ const form = toProfileForm({+ ...emptyPayload,+ hourlyRate: { amountMicros: 150000000, currencyCode: 'USD' },+ });+ expect(toSaveBody(form).hourlyRate).toEqual({ amountMicros: 150000000, currencyCode: 'USD' });+ });+});diff --git a/packages/twenty-apps/internal/twenty-partners/src/modules/partner/self-service/front-components/my-profile/profile-form.ts b/packages/twenty-apps/internal/twenty-partners/src/modules/partner/self-service/front-components/my-profile/profile-form.tsnew file mode 100644index 00000000000..976405896f9--- /dev/null+++ b/packages/twenty-apps/internal/twenty-partners/src/modules/partner/self-service/front-components/my-profile/profile-form.ts@@ -0,0 +1,94 @@+import type { MyProfilePayload } from './types';++// Narrowed from the loader's payload so a field rename upstream breaks the build here.+export type ProfilePayload = Pick<+ MyProfilePayload,+ | 'id'+ | 'name'+ | 'profilePictureUrl'+ | 'introduction'+ | 'city'+ | 'country'+ | 'languagesSpoken'+ | 'region'+ | 'partnerScope'+ | 'skills'+ | 'typeOfTeam'+ | 'availability'+ | 'hourlyRate'+ | 'projectBudgetMin'+ | 'website'+ | 'linkedin'+ | 'calendarLink'+>;++export type Currency = MyProfilePayload['hourlyRate'];++export type MoneyField = { amount: number | null; currencyCode: string };++export type ProfileForm = {+ name: string;+ introduction: string;+ availability: string;+ typeOfTeam: string;+ hourlyRate: MoneyField;+ projectBudgetMin: MoneyField;+ partnerScope: string[];+ skills: string[];+ languagesSpoken: string[];+ region: string[];+ country: string;+ city: string;+ website: string;+ linkedin: string;+ calendarLink: string;+};++const MICROS = 1_000_000;++export const toMoneyField = (value: Currency): MoneyField => ({+ amount: value?.amountMicros != null ? value.amountMicros / MICROS : null,+ currencyCode: value?.currencyCode ?? 'USD',+});++export const toProfileForm = (profile: ProfilePayload): ProfileForm => ({+ name: profile.name ?? '',+ introduction: profile.introduction ?? '',+ availability: profile.availability ?? '',+ typeOfTeam: profile.typeOfTeam ?? '',+ hourlyRate: toMoneyField(profile.hourlyRate),+ projectBudgetMin: toMoneyField(profile.projectBudgetMin),+ partnerScope: profile.partnerScope ?? [],+ skills: profile.skills ?? [],+ languagesSpoken: profile.languagesSpoken ?? [],+ region: profile.region ?? [],+ country: profile.country ?? '',+ city: profile.city ?? '',+ website: profile.website ?? '',+ linkedin: profile.linkedin ?? '',+ calendarLink: profile.calendarLink ?? '',+});++export const toMicros = (money: MoneyField) =>+ money.amount == null+ ? null+ : { amountMicros: Math.round(money.amount * MICROS), currencyCode: money.currencyCode || 'USD' };++// Enum/country selectors send null (not '') when reset to blank so the field clears.+export const toSaveBody = (form: ProfileForm): Record<string, unknown> => ({+ name: form.name,+ introduction: form.introduction,+ city: form.city,+ languagesSpoken: form.languagesSpoken,+ region: form.region,+ partnerScope: form.partnerScope,+ skills: form.skills,+ website: form.website,+ linkedin: form.linkedin,+ calendarLink: form.calendarLink,+ hourlyRate: toMicros(form.hourlyRate),+ projectBudgetMin: toMicros(form.projectBudgetMin),+ availability: form.availability === '' ? null : form.availability,+ typeOfTeam: form.typeOfTeam === '' ? null : form.typeOfTeam,+ country: form.country === '' ? null : form.country,+});diff --git a/packages/twenty-apps/internal/twenty-partners/src/modules/partner/self-service/mappers/save-my-partner-profile.mapper.test.ts b/packages/twenty-apps/internal/twenty-partners/src/modules/partner/self-service/mappers/save-my-partner-profile.mapper.test.tsindex 48e223e69b3..29b5c40f6c8 100644--- a/packages/twenty-apps/internal/twenty-partners/src/modules/partner/self-service/mappers/save-my-partner-profile.mapper.test.ts+++ b/packages/twenty-apps/internal/twenty-partners/src/modules/partner/self-service/mappers/save-my-partner-profile.mapper.test.ts@@ -16,9 +16,9 @@ describe('saveProfileSchema', () => {expect(saveProfileSchema.safeParse({}).success).toBe(true);});- it('rejects an unknown key (region)', () => {- const parsed = saveProfileSchema.safeParse({ region: ['EUROPE'] });- expect(parsed.success).toBe(false);+ it('accepts a region array', () => {+ const parsed = saveProfileSchema.safeParse({ region: ['EUROPE', 'MENA'] });+ expect(parsed.success).toBe(true);});it('rejects an unknown key (validationStage)', () => {@@ -101,6 +101,15 @@ describe('validateProfileOptionValues', () => {it('accepts a null country (clearing it)', () => {expect(validateProfileOptionValues({ country: null })).toBeNull();});++ it('rejects an unknown region', () => {+ const result = validateProfileOptionValues({ region: ['EUROPE', 'ATLANTIS'] });+ expect(result).toEqual({ error: 'Unknown region: ATLANTIS' });+ });++ it('accepts known regions', () => {+ expect(validateProfileOptionValues({ region: ['EUROPE', 'MENA'] })).toBeNull();+ });});describe('buildPartnerUpdateData', () => {@@ -166,4 +175,15 @@ describe('buildPartnerUpdateData', () => {it('returns an empty object for an empty input', () => {expect(buildPartnerUpdateData({})).toEqual({});});++ it('maps region values as provided', () => {+ expect(buildPartnerUpdateData({ region: ['EUROPE', 'MENA'] }).region).toEqual([+ 'EUROPE',+ 'MENA',+ ]);+ });++ it('leaves region off the payload when absent', () => {+ expect('region' in buildPartnerUpdateData({ name: 'Nine Dots Ventures' })).toBe(false);+ });});diff --git a/packages/twenty-apps/internal/twenty-partners/src/modules/partner/self-service/mappers/save-my-partner-profile.mapper.ts b/packages/twenty-apps/internal/twenty-partners/src/modules/partner/self-service/mappers/save-my-partner-profile.mapper.tsindex f8fe1c73b1b..46f0e320697 100644--- a/packages/twenty-apps/internal/twenty-partners/src/modules/partner/self-service/mappers/save-my-partner-profile.mapper.ts+++ b/packages/twenty-apps/internal/twenty-partners/src/modules/partner/self-service/mappers/save-my-partner-profile.mapper.ts@@ -25,6 +25,7 @@ export const saveProfileSchema = zcountry: z.string().nullable().optional(),languagesSpoken: z.array(z.string()).optional(),partnerScope: z.array(z.string()).optional(),+ region: z.array(z.string()).optional(),skills: z.array(z.string()).optional(),typeOfTeam: z.enum(['SOLO', 'AGENCY']).nullable().optional(),availability: z.enum(['AVAILABLE', 'UNAVAILABLE']).nullable().optional(),@@ -44,6 +45,7 @@ const optionValueSet = (options: { value: string }[]): Set<string> =>const COUNTRY_VALUES = optionValueSet(PROFILE_OPTIONS.country);const LANGUAGE_VALUES = optionValueSet(PROFILE_OPTIONS.languagesSpoken);const PARTNER_SCOPE_VALUES = optionValueSet(PROFILE_OPTIONS.partnerScope);+const REGION_VALUES = optionValueSet(PROFILE_OPTIONS.region);// Kept separate from buildPartnerUpdateData so each concern (validation vs.// mapping) is independently unit-testable.@@ -61,6 +63,10 @@ export function validateProfileOptionValues(const unknown = input.partnerScope.find((value) => !PARTNER_SCOPE_VALUES.has(value));if (unknown !== undefined) return { error: `Unknown partner scope: ${unknown}` };}+ if (input.region !== undefined) {+ const unknown = input.region.find((value) => !REGION_VALUES.has(value));+ if (unknown !== undefined) return { error: `Unknown region: ${unknown}` };+ }return null;}@@ -88,6 +94,9 @@ export function buildPartnerUpdateData((value) => value as CoreSchema.PartnerPartnerScopeEnum,);}+ if (input.region !== undefined) {+ data.region = input.region.map((value) => value as CoreSchema.PartnerRegionEnum);+ }if (input.skills !== undefined) data.skills = input.skills;if (input.typeOfTeam !== undefined) data.typeOfTeam = input.typeOfTeam;if (input.availability !== undefined) data.availability = input.availability;