Skip to content

Commit

Permalink
refactor: improve component naming consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
beeman committed Jan 7, 2024
1 parent 3467b9b commit a689f64
Show file tree
Hide file tree
Showing 147 changed files with 1,149 additions and 1,092 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,6 @@ pnpm nx g web-feature company
CREATE libs/web/company/data-access/...
CREATE libs/web/company/feature/...
CREATE libs/web/company/ui/...
UPDATE libs/web/shell/feature/src/lib/web-admin.routes.tsx
UPDATE libs/web/shell/feature/src/lib/shell-admin-routes.tsx
UPDATE tsconfig.base.json
```
1 change: 1 addition & 0 deletions api-schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ type User {
createdAt: DateTime
developer: Boolean
id: String!
identities: [Identity!]
name: String
profileUrl: String
role: UserRole
Expand Down
4 changes: 2 additions & 2 deletions apps/web/src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { WebShellFeature } from '@pubkey-stack/web-shell-feature'
import { ShellFeature } from '@pubkey-stack/web-shell-feature'
import { StrictMode } from 'react'
import * as ReactDOM from 'react-dom/client'

Expand All @@ -12,6 +12,6 @@ if (typeof window !== 'undefined' && typeof window.global === 'undefined' && typ
const root = ReactDOM.createRoot(document.getElementById('root') as HTMLElement)
root.render(
<StrictMode>
<WebShellFeature />
<ShellFeature />
</StrictMode>,
)
8 changes: 6 additions & 2 deletions libs/api/core/data-access/src/lib/api-core-config.service.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import { Injectable, Logger } from '@nestjs/common'
import { ConfigService } from '@nestjs/config'
import { IdentityProvider } from '@prisma/client'
import { CookieOptions } from 'express-serve-static-core'
import { ApiCoreConfig } from './config/configuration'
import { AppConfig } from './entity/app-config.entity'
import { IdentityProvider } from '@prisma/client'

@Injectable()
export class ApiCoreConfigService {
private readonly logger = new Logger(ApiCoreConfigService.name)
constructor(private readonly service: ConfigService<ApiCoreConfig>) {}
constructor(private readonly service: ConfigService<ApiCoreConfig>) {
if (this.authRegisterEnabled && !this.authPasswordEnabled) {
throw new Error('Configuration error: Cannot enable AUTH_REGISTER_ENABLED without enabling AUTH_PASSWORD_ENABLED')
}
}

get appConfig(): AppConfig {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ export function getIdentityUrl(identity: Identity) {
switch (identity.provider) {
case IdentityProvider.Discord:
return `https://discord.com/users/${identity.providerId}`
case IdentityProvider.GitHub:
return `https://github.com/${(identity.profile as unknown as { username: string })?.username}`
case IdentityProvider.Solana:
return `https://explorer.solana.com/address/${identity.providerId}`
default:
Expand Down
13 changes: 9 additions & 4 deletions libs/api/user/data-access/src/lib/api-admin-user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,20 @@ export class ApiAdminUserService {
constructor(private readonly core: ApiCoreService) {}

async createUser(input: AdminCreateUserInput): Promise<PrismaUser> {
const username = slugifyId(input.username)
if (!username.length) {
throw new Error(`Username ${input.username} is not valid`)
}
const exists = await this.core.data.user.findUnique({
where: { username: input.username },
where: { username: username },
})
if (exists) {
throw new Error(`User ${input.username} already exists`)
throw new Error(`User ${username} already exists`)
}
return this.core.data.user.create({
data: {
username: input.username,
password: input.password ? hashPassword(input.username) : undefined,
username,
password: input.password ? hashPassword(input.password) : undefined,
},
})
}
Expand All @@ -43,6 +47,7 @@ export class ApiAdminUserService {
.paginate({
orderBy: { createdAt: 'desc' },
where: getAdminUserWhereInput(input),
include: { identities: true },
})
.withPages({ limit: input.limit, page: input.page })
.then(([data, meta]) => ({ data, meta }))
Expand Down
4 changes: 3 additions & 1 deletion libs/api/user/data-access/src/lib/entity/user.entity.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Field, ObjectType } from '@nestjs/graphql'
import { Field, HideField, ObjectType } from '@nestjs/graphql'
import { UserRole } from './user-role.enum'
import { UserStatus } from './user-status.enum'

Expand All @@ -22,4 +22,6 @@ export class User {
name?: string | null
@Field({ nullable: true })
username!: string
@HideField()
identities?: unknown[] | null
}
6 changes: 6 additions & 0 deletions libs/api/user/feature/src/lib/api-user.resolver.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Parent, ResolveField, Resolver } from '@nestjs/graphql'
import { Identity } from '@pubkey-stack/api-identity-data-access'
import { User } from '@pubkey-stack/api-user-data-access'

@Resolver(() => User)
Expand All @@ -12,4 +13,9 @@ export class ApiUserResolver {
profileUrl(@Parent() user: User) {
return ['/profile', user.username].join('/')
}

@ResolveField(() => [Identity], { nullable: true })
identities(@Parent() user: User) {
return user.identities ?? []
}
}
18 changes: 18 additions & 0 deletions libs/sdk/src/generated/graphql-sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ export type User = {
createdAt?: Maybe<Scalars['DateTime']['output']>
developer?: Maybe<Scalars['Boolean']['output']>
id: Scalars['String']['output']
identities?: Maybe<Array<Identity>>
name?: Maybe<Scalars['String']['output']>
profileUrl?: Maybe<Scalars['String']['output']>
role?: Maybe<UserRole>
Expand Down Expand Up @@ -689,6 +690,19 @@ export type AdminFindManyUserQuery = {
status?: UserStatus | null
updatedAt?: Date | null
username?: string | null
identities?: Array<{
__typename?: 'Identity'
createdAt: Date
expired?: boolean | null
id: string
name?: string | null
profile?: any | null
provider: IdentityProvider
providerId: string
updatedAt: Date
url?: string | null
verified?: boolean | null
}> | null
}>
meta: {
__typename?: 'PagingMeta'
Expand Down Expand Up @@ -1026,13 +1040,17 @@ export const AdminFindManyUserDocument = gql`
paging: adminFindManyUser(input: $input) {
data {
...UserDetails
identities {
...IdentityDetails
}
}
meta {
...PagingMetaDetails
}
}
}
${UserDetailsFragmentDoc}
${IdentityDetailsFragmentDoc}
${PagingMetaDetailsFragmentDoc}
`
export const AdminFindOneUserDocument = gql`
Expand Down
3 changes: 3 additions & 0 deletions libs/sdk/src/graphql/feature-user.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ query adminFindManyUser($input: AdminFindManyUserInput!) {
paging: adminFindManyUser(input: $input) {
data {
...UserDetails
identities {
...IdentityDetails
}
}
meta {
...PagingMetaDetails
Expand Down
1 change: 1 addition & 0 deletions libs/sdk/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './generated/graphql-sdk'
export * from './lib/constants'
export * from './lib/ellipsify'
export * from './lib/get-enum-options'
export * from './lib/get-graphql-client'
Expand Down
4 changes: 4 additions & 0 deletions libs/sdk/src/lib/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const solanaPurple = '#9945FF'
export const solanaGreen = '#14F195'

export const solanaGradient = { from: solanaPurple, to: solanaGreen, deg: 90 }
6 changes: 2 additions & 4 deletions libs/web/auth/data-access/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
export * from './lib/auth-guard'
export * from './lib/web-auth.provider'
export * from './lib/user-role.guard'
export * from './lib/user-status.guard'
export * from './lib/use-me'
export * from './lib/auth.provider'
27 changes: 0 additions & 27 deletions libs/web/auth/data-access/src/lib/auth-guard.tsx

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { AppConfig, LoginInput, RegisterInput, User } from '@pubkey-stack/sdk'
import { useMeQuery, useWebSdk } from '@pubkey-stack/web-shell-data-access'
import { useSdk } from '@pubkey-stack/web-core-data-access'
import { toastError, toastSuccess } from '@pubkey-ui/core'
import { useQuery } from '@tanstack/react-query'

import { createContext, ReactNode, useContext, useEffect, useReducer } from 'react'
import { useMe } from './use-me'

type AuthStatus = 'authenticated' | 'unauthenticated' | 'loading' | 'error'

Expand Down Expand Up @@ -65,17 +65,17 @@ function authReducer(state: WebAuthState, { type, payload }: WebAuthAction): Web
}

export function useAppConfig() {
const sdk = useWebSdk()
const sdk = useSdk()

return useQuery({
queryKey: ['app-config'],
queryFn: () => sdk.appConfig().then((res) => res.data),
})
}

export function WebAuthProvider({ children }: { children: ReactNode }) {
const sdk = useWebSdk()
const query = useMeQuery(sdk)
export function AuthProvider({ children }: { children: ReactNode }) {
const sdk = useSdk()
const me = useMe(sdk)
const configQuery = useAppConfig()

const [state, dispatch] = useReducer(authReducer, { status: 'loading' })
Expand All @@ -86,9 +86,9 @@ export function WebAuthProvider({ children }: { children: ReactNode }) {
}

useEffect(() => {
if (query.isLoading) return
dispatchUser(query.data?.me)
}, [query.isLoading, query.data?.me])
if (me.isLoading) return
dispatchUser(me.data?.me)
}, [me.isLoading, me.data?.me])

const value: WebAuthProviderContext = {
appConfig: configQuery.data?.config,
Expand All @@ -99,6 +99,7 @@ export function WebAuthProvider({ children }: { children: ReactNode }) {
user: state.user,
status: state.status,
loading: state.status === 'loading',

login: (input: LoginInput) =>
sdk
.login({ input })
Expand Down Expand Up @@ -131,7 +132,7 @@ export function WebAuthProvider({ children }: { children: ReactNode }) {
dispatch({ type: 'error', payload: err })
return undefined
}),
refresh: async () => query.refetch().then((res) => dispatchUser(res.data?.me)),
refresh: async () => me.refetch().then((res) => dispatchUser(res.data?.me)),
register: (input: RegisterInput) =>
sdk
.register({ input })
Expand All @@ -153,6 +154,6 @@ export function WebAuthProvider({ children }: { children: ReactNode }) {
return <Context.Provider value={value}>{children}</Context.Provider>
}

export function useWebAuth() {
export function useAuth() {
return useContext(Context)
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Sdk } from '@pubkey-stack/sdk'
import { useQuery } from '@tanstack/react-query'

export function useMeQuery(sdk: Sdk) {
export function useMe(sdk: Sdk) {
return useQuery({
queryKey: ['me'],
queryFn: async () => {
Expand Down
10 changes: 0 additions & 10 deletions libs/web/auth/data-access/src/lib/user-role.guard.tsx

This file was deleted.

10 changes: 0 additions & 10 deletions libs/web/auth/data-access/src/lib/user-status.guard.tsx

This file was deleted.

4 changes: 2 additions & 2 deletions libs/web/auth/feature/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { lazy } from 'react'

export const WebAuthLoginFeature = lazy(() => import('./lib/web-auth-login.feature'))
export const WebAuthRegisterFeature = lazy(() => import('./lib/web-auth-register.feature'))
export const AuthLoginFeature = lazy(() => import('./lib/auth-login-feature'))
export const AuthRegisterFeature = lazy(() => import('./lib/auth-register-feature'))
Loading

0 comments on commit a689f64

Please sign in to comment.