fix: add check for already existing name upon creating board (#1887)
This commit is contained in:
@@ -9,12 +9,15 @@ import { createBoardSchemaValidation } from '~/validations/boards';
|
|||||||
|
|
||||||
export const CreateBoardModal = ({ id }: ContextModalProps<{}>) => {
|
export const CreateBoardModal = ({ id }: ContextModalProps<{}>) => {
|
||||||
const { t } = useTranslation('manage/boards');
|
const { t } = useTranslation('manage/boards');
|
||||||
const utils = api.useContext();
|
const utils = api.useUtils();
|
||||||
const { isLoading, mutate } = api.config.save.useMutation({
|
const { isLoading, mutate } = api.config.save.useMutation({
|
||||||
onSuccess: async () => {
|
onSuccess: async () => {
|
||||||
await utils.boards.all.invalidate();
|
await utils.boards.all.invalidate();
|
||||||
modals.close(id);
|
modals.close(id);
|
||||||
},
|
},
|
||||||
|
onError: async (error) => {
|
||||||
|
form.setFieldError('name', error.message);
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const { i18nZodResolver } = useI18nZodResolver();
|
const { i18nZodResolver } = useI18nZodResolver();
|
||||||
@@ -31,6 +34,7 @@ export const CreateBoardModal = ({ id }: ContextModalProps<{}>) => {
|
|||||||
mutate({
|
mutate({
|
||||||
name: form.values.name,
|
name: form.values.name,
|
||||||
config: fallbackConfig,
|
config: fallbackConfig,
|
||||||
|
create: true,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -59,7 +63,7 @@ export const CreateBoardModal = ({ id }: ContextModalProps<{}>) => {
|
|||||||
<Button
|
<Button
|
||||||
type="submit"
|
type="submit"
|
||||||
onClick={async () => {
|
onClick={async () => {
|
||||||
umami.track('Create new board')
|
umami.track('Create new board');
|
||||||
}}
|
}}
|
||||||
disabled={isLoading}
|
disabled={isLoading}
|
||||||
variant="light"
|
variant="light"
|
||||||
|
|||||||
@@ -19,15 +19,15 @@ export const configRouter = createTRPCRouter({
|
|||||||
.input(
|
.input(
|
||||||
z.object({
|
z.object({
|
||||||
name: configNameSchema,
|
name: configNameSchema,
|
||||||
}),
|
})
|
||||||
)
|
)
|
||||||
.output(z.object({ message: z.string() }))
|
.output(z.object({ message: z.string() }))
|
||||||
.mutation(async ({ input }) => {
|
.mutation(async ({ input }) => {
|
||||||
if (input.name.toLowerCase() === 'default') {
|
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({
|
throw new TRPCError({
|
||||||
code: 'FORBIDDEN',
|
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 the target is not in the list of files, return an error
|
||||||
if (!matchedFile) {
|
if (!matchedFile) {
|
||||||
Consola.error(
|
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({
|
throw new TRPCError({
|
||||||
code: 'NOT_FOUND',
|
code: 'NOT_FOUND',
|
||||||
@@ -64,9 +64,13 @@ export const configRouter = createTRPCRouter({
|
|||||||
z.object({
|
z.object({
|
||||||
name: configNameSchema,
|
name: configNameSchema,
|
||||||
config: z.custom<ConfigType>((x) => !!x && typeof x === 'object'),
|
config: z.custom<ConfigType>((x) => !!x && typeof x === 'object'),
|
||||||
}),
|
create: z.boolean().optional(),
|
||||||
|
})
|
||||||
)
|
)
|
||||||
.mutation(async ({ input }) => {
|
.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.`);
|
Consola.info(`Saving updated configuration of '${input.name}' config.`);
|
||||||
|
|
||||||
const previousConfig = getConfig(input.name);
|
const previousConfig = getConfig(input.name);
|
||||||
@@ -96,16 +100,16 @@ export const configRouter = createTRPCRouter({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const previousApp = previousConfig.apps.find(
|
const previousApp = previousConfig.apps.find(
|
||||||
(previousApp) => previousApp.id === app.id,
|
(previousApp) => previousApp.id === app.id
|
||||||
);
|
);
|
||||||
|
|
||||||
const previousProperty = previousApp?.integration?.properties.find(
|
const previousProperty = previousApp?.integration?.properties.find(
|
||||||
(previousProperty) => previousProperty.field === property.field,
|
(previousProperty) => previousProperty.field === property.field
|
||||||
);
|
);
|
||||||
|
|
||||||
if (property.value !== undefined && property.value !== null) {
|
if (property.value !== undefined && property.value !== null) {
|
||||||
Consola.info(
|
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 {
|
return {
|
||||||
field: property.field,
|
field: property.field,
|
||||||
@@ -168,13 +172,14 @@ export const configRouter = createTRPCRouter({
|
|||||||
path: '/configs/byName',
|
path: '/configs/byName',
|
||||||
tags: ['config'],
|
tags: ['config'],
|
||||||
deprecated: true,
|
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(
|
.input(
|
||||||
z.object({
|
z.object({
|
||||||
name: configNameSchema,
|
name: configNameSchema,
|
||||||
}),
|
})
|
||||||
)
|
)
|
||||||
.output(z.custom<ConfigType>())
|
.output(z.custom<ConfigType>())
|
||||||
.query(async ({ ctx, input }) => {
|
.query(async ({ ctx, input }) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user