Skip to content

Commit

Permalink
feat: add profile label service
Browse files Browse the repository at this point in the history
  • Loading branch information
benfurber committed Oct 23, 2024
1 parent df60d45 commit 65856b3
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 40 deletions.
1 change: 1 addition & 0 deletions shared/data/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './profileTags'
34 changes: 34 additions & 0 deletions shared/data/profileTags.ts
Original file line number Diff line number Diff line change
@@ -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',
},
]
1 change: 1 addition & 0 deletions shared/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './data'
export * from './models'
export * from './messages'
export * from './mocks'
Expand Down
14 changes: 0 additions & 14 deletions shared/mocks/data/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,15 +191,13 @@ export const users = {
_id: 'settings_community_new',
profileType: null,
coverImages: [],
isExpert: null,
collectedPlasticTypes: null,
openingHours: [],
location: null,
verified: true,
_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,
Expand All @@ -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,
Expand All @@ -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',
Expand All @@ -247,7 +242,6 @@ export const users = {
_id: 'settings_member_new',
profileType: null,
coverImages: [],
isExpert: null,
collectedPlasticTypes: null,
openingHours: [],
location: null,
Expand All @@ -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,
Expand All @@ -277,7 +270,6 @@ export const users = {
_id: 'settings_plastic_new',
profileType: null,
coverImages: [],
isExpert: null,
},
settings_workplace_empty: {
collectedPlasticTypes: [],
Expand All @@ -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,
Expand All @@ -300,7 +291,6 @@ export const users = {
_id: 'settings_workplace_empty',
profileType: 'workspace',
coverImages: [],
isExpert: null,
},
settings_workplace_new: {
openingHours: [],
Expand All @@ -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,
Expand All @@ -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',
Expand Down Expand Up @@ -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,
Expand All @@ -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',
Expand Down
4 changes: 2 additions & 2 deletions shared/models/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion shared/models/tags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
24 changes: 7 additions & 17 deletions shared/models/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -109,13 +110,6 @@ export type PlasticTypeLabel =
| 'ps'
| 'other'

export type MachineBuilderXpLabel =
| 'electronics'
| 'machining'
| 'welding'
| 'assembling'
| 'mould-making'

export type WorkspaceType =
| 'shredder'
| 'sheetpress'
Expand Down Expand Up @@ -143,10 +137,6 @@ export interface IWorkspaceType {
subText?: string
}

export interface IMAchineBuilderXp {
label: MachineBuilderXpLabel
}

export interface IOpeningHours {
day: string
openFrom: string
Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions src/pages/Research/Content/ResearchArticle.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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',
})
Expand All @@ -281,7 +281,7 @@ describe('Research Article', () => {
await waitFor(() => {
expect(() =>
wrapper.getAllByText(
`${formatDistanceToNow(update._modified, { addSuffix: true })}`,
`${formatDistanceToNow(_created, { addSuffix: true })}`,
),
).toThrow()
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -27,7 +27,7 @@ export const ContentAuthorTimestamp = ({
action={action}
/>
<Text
hidden={created === modified}
hidden={created === modified || !modified}
variant="auxiliary"
sx={{
color: 'lightgrey',
Expand Down
11 changes: 11 additions & 0 deletions src/services/user.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { profileTags } from 'oa-shared'

import type { ITag } from 'oa-shared'

const getProfileTags: () => ITag[] = () => {
return profileTags
}

export const userService = {
getProfileTags,
}

0 comments on commit 65856b3

Please sign in to comment.