fix: add check for already existing name upon creating board (#1887)

This commit is contained in:
Tagaishi
2024-02-09 22:30:03 +01:00
committed by GitHub
parent cefa0d8fde
commit 02249d20c2
2 changed files with 22 additions and 13 deletions

View File

@@ -9,12 +9,15 @@ import { createBoardSchemaValidation } from '~/validations/boards';
export const CreateBoardModal = ({ id }: ContextModalProps<{}>) => {
const { t } = useTranslation('manage/boards');
const utils = api.useContext();
const utils = api.useUtils();
const { isLoading, mutate } = api.config.save.useMutation({
onSuccess: async () => {
await utils.boards.all.invalidate();
modals.close(id);
},
onError: async (error) => {
form.setFieldError('name', error.message);
},
});
const { i18nZodResolver } = useI18nZodResolver();
@@ -31,6 +34,7 @@ export const CreateBoardModal = ({ id }: ContextModalProps<{}>) => {
mutate({
name: form.values.name,
config: fallbackConfig,
create: true,
});
};
@@ -59,7 +63,7 @@ export const CreateBoardModal = ({ id }: ContextModalProps<{}>) => {
<Button
type="submit"
onClick={async () => {
umami.track('Create new board')
umami.track('Create new board');
}}
disabled={isLoading}
variant="light"

View File

@@ -19,15 +19,15 @@ export const configRouter = createTRPCRouter({
.input(
z.object({
name: configNameSchema,
}),
})
)
.output(z.object({ message: z.string() }))
.mutation(async ({ input }) => {
if (input.name.toLowerCase() === 'default') {
Consola.error('Rejected config deletion because default configuration can\'t be deleted');
Consola.error("Rejected config deletion because default configuration can't be deleted");
throw new TRPCError({
code: 'FORBIDDEN',
message: 'Default config can\'t be deleted',
message: "Default config can't be deleted",
});
}
@@ -44,7 +44,7 @@ export const configRouter = createTRPCRouter({
// If the target is not in the list of files, return an error
if (!matchedFile) {
Consola.error(
`Rejected config deletion request because config name '${input.name}' was not included in present configurations`,
`Rejected config deletion request because config name '${input.name}' was not included in present configurations`
);
throw new TRPCError({
code: 'NOT_FOUND',
@@ -64,9 +64,13 @@ export const configRouter = createTRPCRouter({
z.object({
name: configNameSchema,
config: z.custom<ConfigType>((x) => !!x && typeof x === 'object'),
}),
create: z.boolean().optional(),
})
)
.mutation(async ({ input }) => {
if (input.create && configExists(input.name))
throw new TRPCError({ message: 'Config already exists.', code: 'CONFLICT' });
Consola.info(`Saving updated configuration of '${input.name}' config.`);
const previousConfig = getConfig(input.name);
@@ -96,16 +100,16 @@ export const configRouter = createTRPCRouter({
}
const previousApp = previousConfig.apps.find(
(previousApp) => previousApp.id === app.id,
(previousApp) => previousApp.id === app.id
);
const previousProperty = previousApp?.integration?.properties.find(
(previousProperty) => previousProperty.field === property.field,
(previousProperty) => previousProperty.field === property.field
);
if (property.value !== undefined && property.value !== null) {
Consola.info(
'Detected credential change of private secret. Value will be overwritten in configuration',
'Detected credential change of private secret. Value will be overwritten in configuration'
);
return {
field: property.field,
@@ -168,13 +172,14 @@ export const configRouter = createTRPCRouter({
path: '/configs/byName',
tags: ['config'],
deprecated: true,
summary: 'Retrieve content of the JSON configuration. Deprecated because JSON will be removed in a future version and be replaced with a relational database.'
}
summary:
'Retrieve content of the JSON configuration. Deprecated because JSON will be removed in a future version and be replaced with a relational database.',
},
})
.input(
z.object({
name: configNameSchema,
}),
})
)
.output(z.custom<ConfigType>())
.query(async ({ ctx, input }) => {