diff --git a/apps/backend/src/api/routes/signature.controller.ts b/apps/backend/src/api/routes/signature.controller.ts index 2162443b..e5998956 100644 --- a/apps/backend/src/api/routes/signature.controller.ts +++ b/apps/backend/src/api/routes/signature.controller.ts @@ -1,4 +1,4 @@ -import { Body, Controller, Get, Param, Post, Put } from '@nestjs/common'; +import { Body, Controller, Delete, Get, Param, Post, Put } from '@nestjs/common'; import { GetOrgFromRequest } from '@gitroom/nestjs-libraries/user/org.from.request'; import { Organization } from '@prisma/client'; import { ApiTags } from '@nestjs/swagger'; @@ -28,6 +28,14 @@ export class SignatureController { return this._signatureService.createOrUpdateSignature(org.id, body); } + @Delete('/:id') + async deleteSignature( + @GetOrgFromRequest() org: Organization, + @Param('id') id: string + ) { + return this._signatureService.deleteSignature(org.id, id); + } + @Put('/:id') async updateSignature( @Param('id') id: string, diff --git a/apps/frontend/src/components/settings/signatures.component.tsx b/apps/frontend/src/components/settings/signatures.component.tsx index 403fd32e..3bfa870d 100644 --- a/apps/frontend/src/components/settings/signatures.component.tsx +++ b/apps/frontend/src/components/settings/signatures.component.tsx @@ -12,12 +12,14 @@ import { CopilotTextarea } from '@copilotkit/react-textarea'; import { Select } from '@gitroom/react/form/select'; import { useToaster } from '@gitroom/react/toaster/toaster'; import { useT } from '@gitroom/react/translation/get.transation.service.client'; +import { deleteDialog } from '@gitroom/react/helpers/delete.dialog'; export const SignaturesComponent: FC<{ appendSignature?: (value: string) => void; }> = (props) => { const { appendSignature } = props; const fetch = useFetch(); const modal = useModals(); + const toaster = useToaster(); const load = useCallback(async () => { return (await fetch('/signatures')).json(); }, []); @@ -36,6 +38,27 @@ export const SignaturesComponent: FC<{ [mutate] ); + const deleteSignature = useCallback( + (data: any) => async () => { + if ( + await deleteDialog( + t( + 'are_you_sure_you_want_to_delete', + `Are you sure you want to delete?`, + { name: data.content.slice(0, 15) + '...' } + ) + ) + ) { + await fetch(`/signatures/${data.id}`, { + method: 'DELETE', + }); + mutate(); + toaster.show('Signature deleted successfully', 'success'); + } + }, + [] + ); + const t = useT(); return ( @@ -92,7 +115,7 @@ export const SignaturesComponent: FC<{