From 65856b35b5f2105433f58e86d9e5650a3e1598d1 Mon Sep 17 00:00:00 2001 From: Ben Furber Date: Fri, 11 Oct 2024 10:38:06 +0100 Subject: [PATCH] feat: add profile label service --- shared/data/index.ts | 1 + shared/data/profileTags.ts | 34 +++++++++++++++++++ shared/index.ts | 1 + shared/mocks/data/users.ts | 14 -------- shared/models/db.ts | 4 +-- shared/models/tags.ts | 2 +- shared/models/user.ts | 24 ++++--------- .../Research/Content/ResearchArticle.test.tsx | 8 ++--- .../ContentAuthorTimestamp.tsx | 4 +-- src/services/user.service.ts | 11 ++++++ 10 files changed, 63 insertions(+), 40 deletions(-) create mode 100644 shared/data/index.ts create mode 100644 shared/data/profileTags.ts create mode 100644 src/services/user.service.ts diff --git a/shared/data/index.ts b/shared/data/index.ts new file mode 100644 index 0000000000..1709bdc580 --- /dev/null +++ b/shared/data/index.ts @@ -0,0 +1 @@ +export * from './profileTags' diff --git a/shared/data/profileTags.ts b/shared/data/profileTags.ts new file mode 100644 index 0000000000..8a108d70a5 --- /dev/null +++ b/shared/data/profileTags.ts @@ -0,0 +1,34 @@ +import type { ITag } from '../models/tags' + +export const profileTags: ITag[] = [ + { + _id: 'uCzWZbz3aVKyx2keoqRi', + _created: '2018-01-01T00:00:00.001Z', + _deleted: false, + label: 'Electronics', + }, + { + _id: 'J3LF7fMsDfniYT2ZX3rf', + _created: '2018-01-01T00:00:00.001Z', + _deleted: false, + label: 'Machining', + }, + { + _id: 'QvxszeiUqy867CaVc7Kh', + _created: '2018-01-01T00:00:00.001Z', + _deleted: false, + label: 'Welding', + }, + { + _id: '6h3fWCv3AXGJ4bVr3Foc', + _created: '2018-01-01T00:00:00.001Z', + _deleted: false, + label: 'Assembling', + }, + { + _id: 'FhtRoqZvQYYaN6CN2txJ', + _created: '2018-01-01T00:00:00.001Z', + _deleted: false, + label: 'Mould Making', + }, +] diff --git a/shared/index.ts b/shared/index.ts index a38d7b036e..e5b6b09485 100644 --- a/shared/index.ts +++ b/shared/index.ts @@ -1,3 +1,4 @@ +export * from './data' export * from './models' export * from './messages' export * from './mocks' diff --git a/shared/mocks/data/users.ts b/shared/mocks/data/users.ts index d04366cad0..02fa553398 100644 --- a/shared/mocks/data/users.ts +++ b/shared/mocks/data/users.ts @@ -191,7 +191,6 @@ export const users = { _id: 'settings_community_new', profileType: null, coverImages: [], - isExpert: null, collectedPlasticTypes: null, openingHours: [], location: null, @@ -199,7 +198,6 @@ export const users = { _modified: '2020-01-07T12:15:08.726Z', _created: '2020-01-07T12:15:08.726Z', displayName: 'settings_community_new', - isV4Member: null, _deleted: false, workspaceType: null, country: null, @@ -218,7 +216,6 @@ export const users = { _modified: '2020-01-07T12:14:50.354Z', _created: '2020-01-07T12:14:50.354Z', displayName: 'settings_machine_new', - isV4Member: null, _deleted: false, workspaceType: null, country: null, @@ -231,10 +228,8 @@ export const users = { _id: 'settings_machine_new', profileType: null, coverImages: [], - isExpert: null, }, settings_member_new: { - isV4Member: null, _deleted: false, workspaceType: null, country: 'Poland', @@ -247,7 +242,6 @@ export const users = { _id: 'settings_member_new', profileType: null, coverImages: [], - isExpert: null, collectedPlasticTypes: null, openingHours: [], location: null, @@ -264,7 +258,6 @@ export const users = { _modified: '2020-01-07T12:15:42.218Z', _created: '2020-01-07T12:15:42.218Z', displayName: 'settings_plastic_new', - isV4Member: null, _deleted: false, workspaceType: null, country: null, @@ -277,7 +270,6 @@ export const users = { _id: 'settings_plastic_new', profileType: null, coverImages: [], - isExpert: null, }, settings_workplace_empty: { collectedPlasticTypes: [], @@ -287,7 +279,6 @@ export const users = { _modified: '2020-01-07T12:15:42.218Z', _created: '2020-01-07T12:15:42.218Z', displayName: 'settings_workplace_empty', - isV4Member: null, _deleted: false, workspaceType: null, country: null, @@ -300,7 +291,6 @@ export const users = { _id: 'settings_workplace_empty', profileType: 'workspace', coverImages: [], - isExpert: null, }, settings_workplace_new: { openingHours: [], @@ -309,7 +299,6 @@ export const users = { _modified: '2020-01-07T12:14:15.081Z', _created: '2020-01-07T12:14:15.081Z', displayName: 'settings_workplace_new', - isV4Member: null, _deleted: false, workspaceType: null, country: null, @@ -322,7 +311,6 @@ export const users = { _id: 'settings_workplace_new', profileType: 'workspace', coverImages: [], - isExpert: null, collectedPlasticTypes: null, email: 'settings_workplace_new@test.com', password: 'test1234', @@ -365,7 +353,6 @@ export const users = { _modified: '2020-01-07T12:14:15.081Z', _created: '2020-01-07T12:14:15.081Z', displayName: 'mapview_testing_rejected', - isV4Member: null, _deleted: false, workspaceType: null, country: null, @@ -378,7 +365,6 @@ export const users = { _id: 'mapview_testing_rejected', profileType: 'workspace', coverImages: [], - isExpert: null, collectedPlasticTypes: null, email: 'mapview_testing_rejected@test.com', password: 'mapview_testing_rejected@test.com', diff --git a/shared/models/db.ts b/shared/models/db.ts index c7ab75093c..db01054344 100644 --- a/shared/models/db.ts +++ b/shared/models/db.ts @@ -74,7 +74,7 @@ export type DBEndpoint = keyof typeof DB_ENDPOINTS export interface DBDoc { _id: string _created: ISODateString - _modified: ISODateString + _modified?: ISODateString _deleted: boolean - _contentModifiedTimestamp: ISODateString + _contentModifiedTimestamp?: ISODateString } diff --git a/shared/models/tags.ts b/shared/models/tags.ts index 54486318e2..d68dc98e14 100644 --- a/shared/models/tags.ts +++ b/shared/models/tags.ts @@ -17,5 +17,5 @@ when building tag uploader it should enforce reasonable max size image (say 500p export interface ITag extends DBDoc { label: string - image: string + image?: string } diff --git a/shared/models/user.ts b/shared/models/user.ts index 7830e30b5e..d262e15afe 100644 --- a/shared/models/user.ts +++ b/shared/models/user.ts @@ -3,6 +3,7 @@ import type { DBDoc } from './db' import type { IModerationStatus } from './moderation' import type { INotification, INotificationSettings } from './notifications' import type { IUploadedFileMeta } from './storage' +import type { ISelectedTags } from './tags' /* eslint-disable @typescript-eslint/naming-convention */ export enum UserRole { @@ -109,13 +110,6 @@ export type PlasticTypeLabel = | 'ps' | 'other' -export type MachineBuilderXpLabel = - | 'electronics' - | 'machining' - | 'welding' - | 'assembling' - | 'mould-making' - export type WorkspaceType = | 'shredder' | 'sheetpress' @@ -143,10 +137,6 @@ export interface IWorkspaceType { subText?: string } -export interface IMAchineBuilderXp { - label: MachineBuilderXpLabel -} - export interface IOpeningHours { day: string openFrom: string @@ -193,17 +183,17 @@ export interface IUser { isContactableByPublic?: boolean patreon?: PatreonUser | null totalUseful?: number + total_views?: number + + // New generic profile field for all profile types + tags?: ISelectedTags // Primary PP profile type related fields profileType: ProfileTypeName - workspaceType?: WorkspaceType | null + workspaceType?: WorkspaceType | null // <-- to-do replace with tags + collectedPlasticTypes?: PlasticTypeLabel[] | null // <-- to-do replace with tags mapPinDescription?: string | null openingHours?: IOpeningHours[] - collectedPlasticTypes?: PlasticTypeLabel[] | null - machineBuilderXp?: IMAchineBuilderXp[] | null - isExpert?: boolean | null - isV4Member?: boolean | null - total_views?: number } export interface IUserBadges { diff --git a/src/pages/Research/Content/ResearchArticle.test.tsx b/src/pages/Research/Content/ResearchArticle.test.tsx index 0d9f4d2ef1..bec916ae26 100644 --- a/src/pages/Research/Content/ResearchArticle.test.tsx +++ b/src/pages/Research/Content/ResearchArticle.test.tsx @@ -258,10 +258,10 @@ describe('Research Article', () => { }) it('does not show edit timestamp, when create displays the same value', async () => { - const created = faker.date.past() + const _created = faker.date.past().toString() const update = FactoryResearchItemUpdate({ - _created: created.toString(), - _modified: created.toString(), + _created, + _modified: _created, title: 'A title', description: 'A description', }) @@ -281,7 +281,7 @@ describe('Research Article', () => { await waitFor(() => { expect(() => wrapper.getAllByText( - `${formatDistanceToNow(update._modified, { addSuffix: true })}`, + `${formatDistanceToNow(_created, { addSuffix: true })}`, ), ).toThrow() }) diff --git a/src/pages/common/ContentAuthorTimestamp/ContentAuthorTimestamp.tsx b/src/pages/common/ContentAuthorTimestamp/ContentAuthorTimestamp.tsx index 0066e37834..7ceef203c3 100644 --- a/src/pages/common/ContentAuthorTimestamp/ContentAuthorTimestamp.tsx +++ b/src/pages/common/ContentAuthorTimestamp/ContentAuthorTimestamp.tsx @@ -7,7 +7,7 @@ interface ContentAuthorTimestampProps { userName: string countryCode: string | undefined created: string | number | Date - modified: string | number | Date + modified?: string | number | Date action?: string } @@ -27,7 +27,7 @@ export const ContentAuthorTimestamp = ({ action={action} />