From 81130a546771e25ad821707598eac143583b45c9 Mon Sep 17 00:00:00 2001 From: jamesread Date: Tue, 26 Nov 2024 00:29:52 +0000 Subject: [PATCH 1/3] feature: Configuration variable editor (WIP) --- .../src/api/routes/settings.controller.ts | 10 ++- .../components/layout/settings.component.tsx | 1 + ...onfiguration-variable-editor.component.tsx | 90 +++++++++++++++++++ .../settings/settings.component.tsx | 4 + .../configuration.variable.repository.ts | 40 +++++++++ .../configuration.variable.service.ts | 24 +++++ .../settings/configuration-variables.dto.ts | 16 ++++ 7 files changed, 184 insertions(+), 1 deletion(-) create mode 100644 apps/frontend/src/components/settings/configuration-variable-editor.component.tsx create mode 100644 libraries/nestjs-libraries/src/database/prisma/configuration/configuration.variable.repository.ts create mode 100644 libraries/nestjs-libraries/src/database/prisma/configuration/configuration.variable.service.ts create mode 100644 libraries/nestjs-libraries/src/dtos/settings/configuration-variables.dto.ts diff --git a/apps/backend/src/api/routes/settings.controller.ts b/apps/backend/src/api/routes/settings.controller.ts index e195b242d..b3d92f38a 100644 --- a/apps/backend/src/api/routes/settings.controller.ts +++ b/apps/backend/src/api/routes/settings.controller.ts @@ -8,6 +8,7 @@ import { Sections, } from '@gitroom/backend/services/auth/permissions/permissions.service'; import { OrganizationService } from '@gitroom/nestjs-libraries/database/prisma/organizations/organization.service'; +import { IntegrationTagsService } from '@gitroom/nestjs-libraries/database/prisma/integration.tags/integration.tags.service'; import {AddTeamMemberDto} from "@gitroom/nestjs-libraries/dtos/settings/add.team.member.dto"; import {ApiTags} from "@nestjs/swagger"; @@ -16,7 +17,8 @@ import {ApiTags} from "@nestjs/swagger"; export class SettingsController { constructor( private _starsService: StarsService, - private _organizationService: OrganizationService + private _organizationService: OrganizationService, + private _integrationTagsService: IntegrationTagsService ) {} @Get('/github') @@ -104,6 +106,12 @@ export class SettingsController { return this._starsService.deleteRepository(org.id, id); } + @Get('/integration-tags') + @CheckPolicies([AuthorizationActions.Create, Sections.INTEGRATION_TAGS], [AuthorizationActions.Create, Sections.ADMIN]) + async getIntegrationTags(@GetOrgFromRequest() org: Organization) { + return this._integrationTagsService.getIntegrationTags(org.id); + } + @Get('/team') @CheckPolicies([AuthorizationActions.Create, Sections.TEAM_MEMBERS], [AuthorizationActions.Create, Sections.ADMIN]) async getTeam(@GetOrgFromRequest() org: Organization) { diff --git a/apps/frontend/src/components/layout/settings.component.tsx b/apps/frontend/src/components/layout/settings.component.tsx index f4d56eea2..03bbf066f 100644 --- a/apps/frontend/src/components/layout/settings.component.tsx +++ b/apps/frontend/src/components/layout/settings.component.tsx @@ -14,6 +14,7 @@ import { useToaster } from '@gitroom/react/toaster/toaster'; import { useSWRConfig } from 'swr'; import clsx from 'clsx'; import { TeamsComponent } from '@gitroom/frontend/components/settings/teams.component'; +import { IntegretionTags } from '@gitroom/frontend/components/settings/integration-tags.component'; import { useUser } from '@gitroom/frontend/components/layout/user.context'; import { LogoutComponent } from '@gitroom/frontend/components/layout/logout.component'; import { useSearchParams } from 'next/navigation'; diff --git a/apps/frontend/src/components/settings/configuration-variable-editor.component.tsx b/apps/frontend/src/components/settings/configuration-variable-editor.component.tsx new file mode 100644 index 000000000..407cd584c --- /dev/null +++ b/apps/frontend/src/components/settings/configuration-variable-editor.component.tsx @@ -0,0 +1,90 @@ +'use client'; + +import { FormProvider, SubmitHandler, useForm } from 'react-hook-form'; +import { useFetch } from '@gitroom/helpers/utils/custom.fetch'; +import { useMemo } from 'react'; +import { classValidatorResolver } from '@hookform/resolvers/class-validator'; +import { SaveConfigurationVariableDto, SaveConfigurationVariablesDto } from '@gitroom/nestjs-libraries/dtos/settings/configuration-variables.dto.ts'; + +const cvars = [ + { + key: 'USER_REGISTRATION_ENABLED', + description: 'Enable user registration', + datatype: 'bool', + default: 'true', + val: 'true', + section: ['Functionality'], + }, + { + key: 'MARKETPLACE_ENABLED', + description: 'Enable marketplace', + datatype: 'bool', + default: 'true', + val: 'true', + section: ['Functionality'], + }, + { + key: 'DISCORD_CLIENT_ID', + description: 'Discord client ID', + datatype: 'string', + default: null, + value: null, + section: ['Providers', 'Discord'], + }, + { + key: 'DISCORD_CLIENT_SECRET', + description: 'Discord client secret', + datatype: 'string', + default: null, + value: null, + section: ['Providers', 'Discord'], + }, +] + +export const ConfigurationVariableEditorComponent = () => { + const resolver = useMemo(() => classValidatorResolver(SaveConfigurationVariableDto), []); + + const form = useForm({ resolver, values: { message: '' } }); + + const { data, mutate } = useFetch(`/configuration-variables/all`); + + const submit: SubmitHandler = async (data) => { + await fetch(`/configuration-variables/${params.id}`, { + method: 'POST', + body: JSON.stringify(data), + }); + mutate(); + form.reset(); + } + + return ( +
+

Configuration Variable Editor

+

This screen is only accessible and editable by super admins, it includes configuration that effects the entire app.

+ +
+ + + {cvars.map((cvar) => ( +
+
+ +

{cvar.description}

+
+
+ {cvar.datatype === 'bool' ? ( + + ) : ( + + )} +
+
+ ))} + +
+
+
+ ) +} diff --git a/apps/frontend/src/components/settings/settings.component.tsx b/apps/frontend/src/components/settings/settings.component.tsx index 051604f12..dd24906a2 100644 --- a/apps/frontend/src/components/settings/settings.component.tsx +++ b/apps/frontend/src/components/settings/settings.component.tsx @@ -4,6 +4,7 @@ import { GithubComponent } from '@gitroom/frontend/components/settings/github.co import { useCallback, useEffect } from 'react'; import { useUser } from '@gitroom/frontend/components/layout/user.context'; import { TeamsComponent } from '@gitroom/frontend/components/settings/teams.component'; +import { IntegrationTagsComponent } from '@gitroom/frontend/components/settings/integration-tags.component'; import { useFetch } from '@gitroom/helpers/utils/custom.fetch'; import useSWR from 'swr'; import { LoadingComponent } from '@gitroom/frontend/components/layout/loading'; @@ -70,6 +71,9 @@ export const SettingsComponent = () => { {/**/} )} + + + {!!user?.tier?.team_members && } ); diff --git a/libraries/nestjs-libraries/src/database/prisma/configuration/configuration.variable.repository.ts b/libraries/nestjs-libraries/src/database/prisma/configuration/configuration.variable.repository.ts new file mode 100644 index 000000000..c38253d20 --- /dev/null +++ b/libraries/nestjs-libraries/src/database/prisma/configuration/configuration.variable.repository.ts @@ -0,0 +1,40 @@ +import { PrismaRepository } from '@gitroom/nestjs-libraries/database/prisma/prisma.service'; +import { Injectable } from '@nestjs/common'; + +@Injectable() +export class ConfigurationVariableRepository { + constructor( + private _configurationVariable: PrismaRepository<'configurationVariables'> + ) {} + + getOrDefault(key: string, defaultValue: string) { + const dbVal = this._configurationVariable.model.configurationVariable.findFirst({ + where: { + key, + }, + }); + + if (dbVal) { + return dbVal; + } else { + return defaultValue; + } + } + + isSet(key: string) { + return !!this._configurationVariable.model.configurationVariable.findFirst({ + where: { + key, + }, + }); + } + + set(key: string, value: string) { + return this._configurationVariable.model.configurationVariable.create({ + data: { + key, + value, + }, + }); + } +} diff --git a/libraries/nestjs-libraries/src/database/prisma/configuration/configuration.variable.service.ts b/libraries/nestjs-libraries/src/database/prisma/configuration/configuration.variable.service.ts new file mode 100644 index 000000000..a38277ff4 --- /dev/null +++ b/libraries/nestjs-libraries/src/database/prisma/configuration/configuration.variable.service.ts @@ -0,0 +1,24 @@ +import { Injectable } from '@nestjs/common'; + +@Injectable() +export class ConfigurationVariableService { + constructor( + private _configurationVariableRepository: ConfigurationVariableRepository, + ) {} + + getOrDefault(key: string, defaultValue: string) { + return this._configurationVariableRepository.getOrDefault(key, defaultValue); + } + + getOrEmpty(key: string) { + return this._configurationVariableRepository.getOrDefault(key, ''); + } + + isSet(key: string) { + return this._configurationVariableRepository.isSet(key); + } + + set(key: string, value: string) { + return this._configurationVariableRepository.set(key, value); + } +} diff --git a/libraries/nestjs-libraries/src/dtos/settings/configuration-variables.dto.ts b/libraries/nestjs-libraries/src/dtos/settings/configuration-variables.dto.ts new file mode 100644 index 000000000..9901f6e23 --- /dev/null +++ b/libraries/nestjs-libraries/src/dtos/settings/configuration-variables.dto.ts @@ -0,0 +1,16 @@ +import {IsDefined, IsString, ValidateNested} from 'class-validator'; +import {Type} from 'class-transformer'; + +export class SaveConfigurationVariableDto { + @IsString() + key: string; + + @IsString() + val: string; +} + +export class SaveConfigurationVariablesDto { + @ValidateNested({each: true}) + @Type(() => ConfigurationVariableDto) + configurationVariables: Record; +} From 43e071f8f7a6c1bef0d156b68de93eb671abacf0 Mon Sep 17 00:00:00 2001 From: jamesread Date: Tue, 26 Nov 2024 09:09:11 +0000 Subject: [PATCH 2/3] feature: Ongoing WIP on configuration variables --- .../src/api/routes/settings.controller.ts | 18 ++-- .../components/layout/settings.component.tsx | 1 - .../src/components/layout/top.menu.tsx | 16 ++-- ...onfiguration-variable-editor.component.tsx | 83 ++++++++----------- .../settings/settings.component.tsx | 4 +- .../configuration.variable.repository.ts | 12 ++- .../configuration.variable.service.ts | 60 +++++++++++++- .../src/database/prisma/database.module.ts | 4 + .../src/database/prisma/schema.prisma | 9 +- 9 files changed, 133 insertions(+), 74 deletions(-) diff --git a/apps/backend/src/api/routes/settings.controller.ts b/apps/backend/src/api/routes/settings.controller.ts index b3d92f38a..1a83699cd 100644 --- a/apps/backend/src/api/routes/settings.controller.ts +++ b/apps/backend/src/api/routes/settings.controller.ts @@ -8,7 +8,7 @@ import { Sections, } from '@gitroom/backend/services/auth/permissions/permissions.service'; import { OrganizationService } from '@gitroom/nestjs-libraries/database/prisma/organizations/organization.service'; -import { IntegrationTagsService } from '@gitroom/nestjs-libraries/database/prisma/integration.tags/integration.tags.service'; +import { ConfigurationVariableService } from '@gitroom/nestjs-libraries/database/prisma/configuration/configuration.variable.service'; import {AddTeamMemberDto} from "@gitroom/nestjs-libraries/dtos/settings/add.team.member.dto"; import {ApiTags} from "@nestjs/swagger"; @@ -18,9 +18,17 @@ export class SettingsController { constructor( private _starsService: StarsService, private _organizationService: OrganizationService, - private _integrationTagsService: IntegrationTagsService + private _configurationVariableService: ConfigurationVariableService ) {} + @Get('/cvars/all') + @CheckPolicies([AuthorizationActions.Create, Sections.ADMIN]) + async getConfigurationVariables() { + return { + configurationVariables: await this._configurationVariableService.getAll(), + }; + } + @Get('/github') @CheckPolicies([AuthorizationActions.Create, Sections.ADMIN]) async getConnectedGithubAccounts(@GetOrgFromRequest() org: Organization) { @@ -106,12 +114,6 @@ export class SettingsController { return this._starsService.deleteRepository(org.id, id); } - @Get('/integration-tags') - @CheckPolicies([AuthorizationActions.Create, Sections.INTEGRATION_TAGS], [AuthorizationActions.Create, Sections.ADMIN]) - async getIntegrationTags(@GetOrgFromRequest() org: Organization) { - return this._integrationTagsService.getIntegrationTags(org.id); - } - @Get('/team') @CheckPolicies([AuthorizationActions.Create, Sections.TEAM_MEMBERS], [AuthorizationActions.Create, Sections.ADMIN]) async getTeam(@GetOrgFromRequest() org: Organization) { diff --git a/apps/frontend/src/components/layout/settings.component.tsx b/apps/frontend/src/components/layout/settings.component.tsx index 03bbf066f..f4d56eea2 100644 --- a/apps/frontend/src/components/layout/settings.component.tsx +++ b/apps/frontend/src/components/layout/settings.component.tsx @@ -14,7 +14,6 @@ import { useToaster } from '@gitroom/react/toaster/toaster'; import { useSWRConfig } from 'swr'; import clsx from 'clsx'; import { TeamsComponent } from '@gitroom/frontend/components/settings/teams.component'; -import { IntegretionTags } from '@gitroom/frontend/components/settings/integration-tags.component'; import { useUser } from '@gitroom/frontend/components/layout/user.context'; import { LogoutComponent } from '@gitroom/frontend/components/layout/logout.component'; import { useSearchParams } from 'next/navigation'; diff --git a/apps/frontend/src/components/layout/top.menu.tsx b/apps/frontend/src/components/layout/top.menu.tsx index 11c7ba6e2..73d97f3a4 100644 --- a/apps/frontend/src/components/layout/top.menu.tsx +++ b/apps/frontend/src/components/layout/top.menu.tsx @@ -33,16 +33,12 @@ export const useMenuItems = () => { }, ] : []), - ...(!isGeneral - ? [ - { - name: 'Settings', - icon: 'settings', - path: '/settings', - role: ['ADMIN', 'SUPERADMIN'], - }, - ] - : []), + { + name: 'Settings', + icon: 'settings', + path: '/settings', + role: ['ADMIN', 'SUPERADMIN'], + }, { name: 'Marketplace', icon: 'marketplace', diff --git a/apps/frontend/src/components/settings/configuration-variable-editor.component.tsx b/apps/frontend/src/components/settings/configuration-variable-editor.component.tsx index 407cd584c..36681eeef 100644 --- a/apps/frontend/src/components/settings/configuration-variable-editor.component.tsx +++ b/apps/frontend/src/components/settings/configuration-variable-editor.component.tsx @@ -1,55 +1,38 @@ 'use client'; import { FormProvider, SubmitHandler, useForm } from 'react-hook-form'; -import { useFetch } from '@gitroom/helpers/utils/custom.fetch'; import { useMemo } from 'react'; import { classValidatorResolver } from '@hookform/resolvers/class-validator'; import { SaveConfigurationVariableDto, SaveConfigurationVariablesDto } from '@gitroom/nestjs-libraries/dtos/settings/configuration-variables.dto.ts'; - -const cvars = [ - { - key: 'USER_REGISTRATION_ENABLED', - description: 'Enable user registration', - datatype: 'bool', - default: 'true', - val: 'true', - section: ['Functionality'], - }, - { - key: 'MARKETPLACE_ENABLED', - description: 'Enable marketplace', - datatype: 'bool', - default: 'true', - val: 'true', - section: ['Functionality'], - }, - { - key: 'DISCORD_CLIENT_ID', - description: 'Discord client ID', - datatype: 'string', - default: null, - value: null, - section: ['Providers', 'Discord'], - }, - { - key: 'DISCORD_CLIENT_SECRET', - description: 'Discord client secret', - datatype: 'string', - default: null, - value: null, - section: ['Providers', 'Discord'], - }, -] +import { Button } from '@gitroom/react/form/button'; +import { FC, useCallback, useEffect, useState } from 'react'; +import useSWR from 'swr'; +import { useFetch } from '@gitroom/helpers/utils/custom.fetch'; export const ConfigurationVariableEditorComponent = () => { const resolver = useMemo(() => classValidatorResolver(SaveConfigurationVariableDto), []); + const fetch = useFetch(); + const form = useForm({ resolver, values: { message: '' } }); - const { data, mutate } = useFetch(`/configuration-variables/all`); + const [state, setState] = useState(true); + + const fetchCvars = useCallback(async () => { + const cvars = await ( + await fetch('/settings/cvars/all', { + method: 'GET', + }) + ).json(); + + setState(cvars); + return cvars; + }, []); + + const { data, error, isLoading } = useSWR('/settings/cvars/all', fetchCvars) const submit: SubmitHandler = async (data) => { - await fetch(`/configuration-variables/${params.id}`, { + await fetch(`/settings/cvars/${params.id}`, { method: 'POST', body: JSON.stringify(data), }); @@ -57,21 +40,27 @@ export const ConfigurationVariableEditorComponent = () => { form.reset(); } + console.log("data", data) + + if (isLoading) return
Loading...
+ if (error) return
Error loading data
+ return (
-

Configuration Variable Editor

+

Configuration Variable Editor

This screen is only accessible and editable by super admins, it includes configuration that effects the entire app.

-
- - - {cvars.map((cvar) => ( -
+ {data.configurationVariables.map((cvar) => ( +

{cvar.description}

+ + {cvar.docs && ( + More docs... + )}
{cvar.datatype === 'bool' ? ( @@ -83,8 +72,8 @@ export const ConfigurationVariableEditorComponent = () => {
))} - - + +
) } diff --git a/apps/frontend/src/components/settings/settings.component.tsx b/apps/frontend/src/components/settings/settings.component.tsx index dd24906a2..0e8bb794e 100644 --- a/apps/frontend/src/components/settings/settings.component.tsx +++ b/apps/frontend/src/components/settings/settings.component.tsx @@ -4,7 +4,7 @@ import { GithubComponent } from '@gitroom/frontend/components/settings/github.co import { useCallback, useEffect } from 'react'; import { useUser } from '@gitroom/frontend/components/layout/user.context'; import { TeamsComponent } from '@gitroom/frontend/components/settings/teams.component'; -import { IntegrationTagsComponent } from '@gitroom/frontend/components/settings/integration-tags.component'; +import { ConfigurationVariableEditorComponent } from '@gitroom/frontend/components/settings/configuration-variable-editor.component'; import { useFetch } from '@gitroom/helpers/utils/custom.fetch'; import useSWR from 'swr'; import { LoadingComponent } from '@gitroom/frontend/components/layout/loading'; @@ -72,7 +72,7 @@ export const SettingsComponent = () => {
)} - + {!!user?.tier?.team_members && }
diff --git a/libraries/nestjs-libraries/src/database/prisma/configuration/configuration.variable.repository.ts b/libraries/nestjs-libraries/src/database/prisma/configuration/configuration.variable.repository.ts index c38253d20..2d9ea53f2 100644 --- a/libraries/nestjs-libraries/src/database/prisma/configuration/configuration.variable.repository.ts +++ b/libraries/nestjs-libraries/src/database/prisma/configuration/configuration.variable.repository.ts @@ -4,11 +4,11 @@ import { Injectable } from '@nestjs/common'; @Injectable() export class ConfigurationVariableRepository { constructor( - private _configurationVariable: PrismaRepository<'configurationVariables'> + private _configurationVariables: PrismaRepository<'configurationVariables'> ) {} getOrDefault(key: string, defaultValue: string) { - const dbVal = this._configurationVariable.model.configurationVariable.findFirst({ + const dbVal = this._configurationVariables.model.configurationVariables.findFirst({ where: { key, }, @@ -22,7 +22,7 @@ export class ConfigurationVariableRepository { } isSet(key: string) { - return !!this._configurationVariable.model.configurationVariable.findFirst({ + return !!this._configurationVariables.model.configurationVariables.findFirst({ where: { key, }, @@ -30,11 +30,15 @@ export class ConfigurationVariableRepository { } set(key: string, value: string) { - return this._configurationVariable.model.configurationVariable.create({ + return this._configurationVariables.model.configurationVariables.create({ data: { key, value, }, }); } + + getAll() { + return this._configurationVariables.model.configurationVariables.findMany(); + } } diff --git a/libraries/nestjs-libraries/src/database/prisma/configuration/configuration.variable.service.ts b/libraries/nestjs-libraries/src/database/prisma/configuration/configuration.variable.service.ts index a38277ff4..b8e3376c1 100644 --- a/libraries/nestjs-libraries/src/database/prisma/configuration/configuration.variable.service.ts +++ b/libraries/nestjs-libraries/src/database/prisma/configuration/configuration.variable.service.ts @@ -1,10 +1,63 @@ import { Injectable } from '@nestjs/common'; +import { ConfigurationVariableRepository } from '@gitroom/nestjs-libraries/database/prisma/configuration/configuration.variable.repository'; + @Injectable() export class ConfigurationVariableService { + private cvars: { + key: string, + title: string, + description: string, + datatype: string, + default: string | null, + val: string | null, + section: string[], + docs?: string, + }[]; + constructor( private _configurationVariableRepository: ConfigurationVariableRepository, - ) {} + ) { + this.cvars = [ + { + key: 'USER_REGISTRATION_DISABLED', + title: 'Disable user registration', + description: 'If user registration is disabled, only super admins can create new users', + datatype: 'bool', + default: 'true', + val: 'true', + section: ['Functionality'], + }, + { + key: 'MARKETPLACE_DISABLED', + title: 'Disable marketplace', + description: 'If the marketplace is disabled, users will not be able to buy or sell posts', + datatype: 'bool', + default: 'true', + val: 'true', + section: ['Functionality'], + }, + { + key: 'DISCORD_CLIENT_ID', + title: 'Discord client ID', + description: 'Used to authenticate with Discord with OAuth.', + docs: 'https://docs.postiz.com/providers/discord', + datatype: 'string', + default: null, + val: null, + section: ['Providers', 'Discord'], + }, + { + key: 'DISCORD_CLIENT_SECRET', + title: 'Discord client secret', + description: 'Used to authenticate with Discord with OAuth.', + datatype: 'string', + default: null, + val: null, + section: ['Providers', 'Discord'], + }, + ] + } getOrDefault(key: string, defaultValue: string) { return this._configurationVariableRepository.getOrDefault(key, defaultValue); @@ -21,4 +74,9 @@ export class ConfigurationVariableService { set(key: string, value: string) { return this._configurationVariableRepository.set(key, value); } + + getAll() { + return this.cvars; +// return this._configurationVariableRepository.getAll(); + } } diff --git a/libraries/nestjs-libraries/src/database/prisma/database.module.ts b/libraries/nestjs-libraries/src/database/prisma/database.module.ts index 99b563858..fd4a3ef6d 100644 --- a/libraries/nestjs-libraries/src/database/prisma/database.module.ts +++ b/libraries/nestjs-libraries/src/database/prisma/database.module.ts @@ -2,6 +2,8 @@ import { Global, Module } from '@nestjs/common'; import { PrismaRepository, PrismaService } from './prisma.service'; import { OrganizationRepository } from '@gitroom/nestjs-libraries/database/prisma/organizations/organization.repository'; import { OrganizationService } from '@gitroom/nestjs-libraries/database/prisma/organizations/organization.service'; +import { ConfigurationVariableRepository } from '@gitroom/nestjs-libraries/database/prisma/configuration/configuration.variable.repository'; +import { ConfigurationVariableService } from '@gitroom/nestjs-libraries/database/prisma/configuration/configuration.variable.service'; import { UsersService } from '@gitroom/nestjs-libraries/database/prisma/users/users.service'; import { UsersRepository } from '@gitroom/nestjs-libraries/database/prisma/users/users.repository'; import { StarsService } from '@gitroom/nestjs-libraries/database/prisma/stars/stars.service'; @@ -41,6 +43,8 @@ import { AgenciesRepository } from '@gitroom/nestjs-libraries/database/prisma/ag UsersRepository, OrganizationService, OrganizationRepository, + ConfigurationVariableService, + ConfigurationVariableRepository, StarsService, StarsRepository, SubscriptionService, diff --git a/libraries/nestjs-libraries/src/database/prisma/schema.prisma b/libraries/nestjs-libraries/src/database/prisma/schema.prisma index a28583301..da52b529c 100644 --- a/libraries/nestjs-libraries/src/database/prisma/schema.prisma +++ b/libraries/nestjs-libraries/src/database/prisma/schema.prisma @@ -439,6 +439,13 @@ model Messages { @@index([deletedAt]) } +model ConfigurationVariables { + key String @unique + value String + + @@index([key]) +} + enum OrderStatus { PENDING ACCEPTED @@ -486,4 +493,4 @@ enum APPROVED_SUBMIT_FOR_ORDER { NO WAITING_CONFIRMATION YES -} \ No newline at end of file +} From d72f6b0d900afc00a568d253f63389a65f23c725 Mon Sep 17 00:00:00 2001 From: jamesread Date: Tue, 26 Nov 2024 09:17:38 +0000 Subject: [PATCH 3/3] Fix various lint errors --- ...onfiguration-variable-editor.component.tsx | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/apps/frontend/src/components/settings/configuration-variable-editor.component.tsx b/apps/frontend/src/components/settings/configuration-variable-editor.component.tsx index 36681eeef..a3b8c2405 100644 --- a/apps/frontend/src/components/settings/configuration-variable-editor.component.tsx +++ b/apps/frontend/src/components/settings/configuration-variable-editor.component.tsx @@ -1,20 +1,20 @@ 'use client'; -import { FormProvider, SubmitHandler, useForm } from 'react-hook-form'; -import { useMemo } from 'react'; -import { classValidatorResolver } from '@hookform/resolvers/class-validator'; -import { SaveConfigurationVariableDto, SaveConfigurationVariablesDto } from '@gitroom/nestjs-libraries/dtos/settings/configuration-variables.dto.ts'; -import { Button } from '@gitroom/react/form/button'; -import { FC, useCallback, useEffect, useState } from 'react'; -import useSWR from 'swr'; -import { useFetch } from '@gitroom/helpers/utils/custom.fetch'; +// import { FormProvider, SubmitHandler, useForm } from 'react-hook-form'; +// import { useMemo } from 'react'; +// import { classValidatorResolver } from '@hookform/resolvers/class-validator'; +// import { SaveConfigurationVariableDto, SaveConfigurationVariablesDto } from '@gitroom/nestjs-libraries/dtos/settings/configuration-variables.dto.ts'; +import { Button } from '@gitroom/react/form/button' +import { useCallback, useState } from 'react' +import useSWR from 'swr' +import { useFetch } from '@gitroom/helpers/utils/custom.fetch' export const ConfigurationVariableEditorComponent = () => { - const resolver = useMemo(() => classValidatorResolver(SaveConfigurationVariableDto), []); + // const resolver = useMemo(() => classValidatorResolver(SaveConfigurationVariableDto), []); const fetch = useFetch(); - const form = useForm({ resolver, values: { message: '' } }); + // const form = useForm({ resolver, values: { message: '' } }); const [state, setState] = useState(true); @@ -27,10 +27,11 @@ export const ConfigurationVariableEditorComponent = () => { setState(cvars); return cvars; - }, []); + }, []) const { data, error, isLoading } = useSWR('/settings/cvars/all', fetchCvars) + /* const submit: SubmitHandler = async (data) => { await fetch(`/settings/cvars/${params.id}`, { method: 'POST', @@ -39,8 +40,7 @@ export const ConfigurationVariableEditorComponent = () => { mutate(); form.reset(); } - - console.log("data", data) + */ if (isLoading) return
Loading...
if (error) return
Error loading data