From 594ba83f844a335608134ae9e28a53d2d36ccbda Mon Sep 17 00:00:00 2001 From: sutterj Date: Mon, 17 Jun 2024 16:46:21 -0400 Subject: [PATCH] fix: use private org for location when set --- .../[organizationId]/forks/[forkId]/page.tsx | 24 +++++++++++---- src/app/api/trpc/trpc-router.ts | 2 ++ .../components/dialog/DeleteMirrorDialog.tsx | 6 ++-- src/server/config/controller.ts | 30 +++++++++++++++++++ src/server/config/router.ts | 11 +++++++ src/server/config/schema.ts | 7 +++++ 6 files changed, 70 insertions(+), 10 deletions(-) create mode 100644 src/server/config/controller.ts create mode 100644 src/server/config/router.ts create mode 100644 src/server/config/schema.ts diff --git a/src/app/[organizationId]/forks/[forkId]/page.tsx b/src/app/[organizationId]/forks/[forkId]/page.tsx index 39b9e80..c19c572 100644 --- a/src/app/[organizationId]/forks/[forkId]/page.tsx +++ b/src/app/[organizationId]/forks/[forkId]/page.tsx @@ -150,6 +150,16 @@ const Fork = () => { const start = pageIndex * pageSize const end = start + pageSize + const { + data: getConfigData, + isLoading: configLoading, + error: configError, + } = trpc.getConfig.useQuery({ + orgId: organizationId as string, + }) + + const orgName = getConfigData?.privateOrg ?? orgData?.login + const { data: createMirrorData, isLoading: createMirrorLoading, @@ -267,7 +277,7 @@ const Fork = () => { await deleteMirror({ mirrorName, orgId: String(orgData?.id), - orgName: orgData?.name ?? '', + orgName: orgName ?? '', }).then((res) => { if (!res.success) { openDeleteErrorFlash() @@ -287,7 +297,7 @@ const Fork = () => { ) // show loading table - if (!mirrors || mirrorsLoading) { + if (!mirrors || mirrorsLoading || configLoading) { return ( @@ -361,6 +371,9 @@ const Fork = () => { {deleteMirrorLoading && } + + {configError && } + {listMirrorsError && } @@ -549,7 +562,7 @@ const Fork = () => { )} { createMirror={handleOnCreateMirror} /> { editMirror={handleOnEditMirror} /> void deleteMirror: (data: { orgId: string - orgName: string + orgLogin: string mirrorName: string }) => void } @@ -18,7 +17,6 @@ interface DeleteMirrorDialogProps { export const DeleteMirrorDialog = ({ orgLogin, orgId, - orgName, mirrorName, isOpen, closeDialog, @@ -36,7 +34,7 @@ export const DeleteMirrorDialog = ({ { content: 'Delete', variant: 'danger', - onClick: () => deleteMirror({ orgId, orgName, mirrorName }), + onClick: () => deleteMirror({ orgId, orgLogin, mirrorName }), }, ]} onClose={closeDialog} diff --git a/src/server/config/controller.ts b/src/server/config/controller.ts new file mode 100644 index 0000000..03e01d4 --- /dev/null +++ b/src/server/config/controller.ts @@ -0,0 +1,30 @@ +import { TRPCError } from '@trpc/server' +import { getConfig } from '../../bot/config' +import { logger } from '../../utils/logger' +import { GetConfigSchema } from './schema' + +const configApiLogger = logger.getSubLogger({ name: 'org-api' }) + +// Get the config values for the given org +export const getConfigHandler = async ({ + input, +}: { + input: GetConfigSchema +}) => { + try { + configApiLogger.info('Fetching config', { ...input }) + + const config = await getConfig(input.orgId) + + configApiLogger.debug('Fetched config', config) + + return config + } catch (error) { + configApiLogger.error('Error fetching config', { error }) + + throw new TRPCError({ + code: 'INTERNAL_SERVER_ERROR', + message: (error as Error).message, + }) + } +} diff --git a/src/server/config/router.ts b/src/server/config/router.ts new file mode 100644 index 0000000..82b8a8b --- /dev/null +++ b/src/server/config/router.ts @@ -0,0 +1,11 @@ +import { procedure, router } from '../../utils/trpc-server' +import { getConfigHandler } from './controller' +import { GetConfigSchema } from './schema' + +const configRouter = router({ + getConfig: procedure + .input(GetConfigSchema) + .query(({ input }) => getConfigHandler({ input })), +}) + +export default configRouter diff --git a/src/server/config/schema.ts b/src/server/config/schema.ts new file mode 100644 index 0000000..3dee6cd --- /dev/null +++ b/src/server/config/schema.ts @@ -0,0 +1,7 @@ +import { z } from 'zod' + +export const GetConfigSchema = z.object({ + orgId: z.string(), +}) + +export type GetConfigSchema = z.TypeOf