Skip to content

Commit

Permalink
refactor: api to server components
Browse files Browse the repository at this point in the history
Signed-off-by: Jeroen Branje <[email protected]>
  • Loading branch information
jeroenbranje committed Jan 25, 2024
1 parent 5a274dc commit b41b742
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 14 deletions.
1 change: 0 additions & 1 deletion apps/envited.ascs.digital/app/api/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { equals, pathOr, prop } from 'ramda'

import { Role, Session, User } from '../../common/types/types'


export const extractIdFromCredential = pathOr('', ['credentialSubject', 'id'])

export const extractIssuerIdFromCredential = pathOr('', ['issuer', 'id'])
Expand Down
1 change: 1 addition & 0 deletions apps/envited.ascs.digital/app/dashboard/users/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { getUsersByIssuerId } from 'apps/envited.ascs.digital/common/server'

import { Users } from '../../../modules/Users'

export default async function Index() {
Expand Down
6 changes: 5 additions & 1 deletion apps/envited.ascs.digital/common/i18n/useI18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ import { Locale, TranslationsMap } from './types'
const getTranslationsForLanguage = (namespace: string) => (locale: Locale) => pathOr({}, [locale, namespace])

const mergeTranslations = reduce(mergeDeepRight, { [Locale.en_GB]: {}, [Locale.de_DE]: {} })
const translationObject = mergeTranslations([HeaderTranslation, HeroHeaderTranslation, UsersTranslation]) as TranslationsMap
const translationObject = mergeTranslations([
HeaderTranslation,
HeroHeaderTranslation,
UsersTranslation,
]) as TranslationsMap

export const translation = (translations: TranslationsMap) => (namespace: string) => {
const t = (key: string): React.ReactElement =>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { isNil } from 'ramda'
import { cache } from 'react'

import { isOwnUser, userIsIssuedByLoggedInUser } from '../utils'
import { getServerSession } from '../../auth'
import { db } from '../../database/queries'
import { Database } from '../../database/types'
import { User } from '../../types'
import { Session } from '../../types/types'
import { badRequestError, error, unauthorizedError } from '../../utils'
import { isOwnUser, userIsIssuedByLoggedInUser } from '../utils'

export const _getUserById =
({ db, getServerSession }: { db: Database; getServerSession: () => Promise<Session | null> }) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('common/server/users/getUsersByIssuerId', () => {
Promise.resolve({
user: {
pkh: 'USER_ISSUER_ID',
role: Role.federator
role: Role.federator,
},
}),
)
Expand All @@ -32,7 +32,9 @@ describe('common/server/users/getUsersByIssuerId', () => {
}),
)

const result = await SUT._getUsersByIssuerId({ db: dbStub, getServerSession: getServerSessionStub })('USER_ISSUER_ID')
const result = await SUT._getUsersByIssuerId({ db: dbStub, getServerSession: getServerSessionStub })(
'USER_ISSUER_ID',
)
expect(result).toEqual([user])
})

Expand Down
1 change: 0 additions & 1 deletion apps/envited.ascs.digital/common/server/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { equals, pathOr, prop } from 'ramda'

import { Role, Session, User } from '../../common/types/types'


export const extractIdFromCredential = pathOr('', ['credentialSubject', 'id'])

export const extractIssuerIdFromCredential = pathOr('', ['issuer', 'id'])
Expand Down
12 changes: 7 additions & 5 deletions apps/envited.ascs.digital/modules/Users/Users.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import { Users } from './Users'

describe('Users', () => {
it('should render successfully', () => {
const USERS_MAP = [{
name: 'John Johnson',
email: '[email protected]',
id: 'did:pkh:tz:tz1SfdVU1mor3Sgej3FmmwMH4HM1EjTzqqeE',
}]
const USERS_MAP = [
{
name: 'John Johnson',
email: '[email protected]',
id: 'did:pkh:tz:tz1SfdVU1mor3Sgej3FmmwMH4HM1EjTzqqeE',
},
]

const { baseElement } = render(<Users users={USERS_MAP} />)
expect(baseElement).toBeTruthy()
Expand Down
6 changes: 3 additions & 3 deletions apps/envited.ascs.digital/modules/Users/Users.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
'use client'

import { Card, Heading, Table, TableBody, TableCell, TableHeader, TableRow } from '@envited-marketplace/design-system'
import { map } from 'ramda'
import React, { FC } from 'react'

import { useTranslation } from '../../common/i18n'
import { User } from '../../common/types/types'
import { map } from 'ramda'

interface UsersProps {
users: Partial<User>[]
Expand All @@ -31,13 +31,13 @@ export const Users: FC<UsersProps> = ({ users }) => {
</TableRow>
</TableHeader>
<TableBody>
{map(({id, name, email }: Partial<User>) =>
{map(({ id, name, email }: Partial<User>) => (
<TableRow key={id}>
<TableCell>{id}</TableCell>
<TableCell>{name}</TableCell>
<TableCell>{email}</TableCell>
</TableRow>
)(users)}
))(users)}
</TableBody>
</Table>
</Card>
Expand Down

0 comments on commit b41b742

Please sign in to comment.