From e2fb6b9155d9e5090ffa95fd99aa8f18764ee807 Mon Sep 17 00:00:00 2001 From: Chris Anderson Date: Tue, 21 Mar 2023 22:13:38 -0500 Subject: [PATCH] Allows for removing locales --- .../platform/src/render/TemplateController.ts | 7 +- apps/platform/src/render/TemplateService.ts | 4 ++ .../src/views/campaign/CreateLocaleModal.tsx | 15 +++-- .../src/views/campaign/EditLocalesModal.tsx | 65 +++++++++++++++++++ apps/ui/src/views/campaign/EmailEditor.css | 4 +- apps/ui/src/views/campaign/EmailEditor.tsx | 10 ++- 6 files changed, 93 insertions(+), 12 deletions(-) create mode 100644 apps/ui/src/views/campaign/EditLocalesModal.tsx diff --git a/apps/platform/src/render/TemplateController.ts b/apps/platform/src/render/TemplateController.ts index 12c422ae..04fb0bbd 100644 --- a/apps/platform/src/render/TemplateController.ts +++ b/apps/platform/src/render/TemplateController.ts @@ -4,7 +4,7 @@ import { JSONSchemaType, validate } from '../core/validate' import { searchParamsSchema } from '../core/searchParams' import { extractQueryParams } from '../utilities' import Template, { TemplateParams, TemplateUpdateParams } from './Template' -import { createTemplate, getTemplate, pagedTemplates, sendProof, updateTemplate } from './TemplateService' +import { createTemplate, deleteTemplate, getTemplate, pagedTemplates, sendProof, updateTemplate } from './TemplateService' import { Variables } from '.' import { User } from '../users/User' import { UserEvent } from '../users/UserEvent' @@ -201,6 +201,11 @@ router.patch('/:templateId', async ctx => { ctx.body = await updateTemplate(ctx.state.template!.id, payload) }) +router.delete('/:templateId', async ctx => { + const template = ctx.state.template! + ctx.body = await deleteTemplate(template.id, template.project_id) +}) + router.post('/:templateId/preview', async ctx => { const payload = ctx.request.body as Variables const template = ctx.state.template!.map() diff --git a/apps/platform/src/render/TemplateService.ts b/apps/platform/src/render/TemplateService.ts index 07531c27..68082239 100644 --- a/apps/platform/src/render/TemplateService.ts +++ b/apps/platform/src/render/TemplateService.ts @@ -43,6 +43,10 @@ export const updateTemplate = async (templateId: number, params: TemplateUpdateP return await Template.updateAndFetch(templateId, prune(params)) } +export const deleteTemplate = async (id: number, projectId: number) => { + return await Template.delete(qb => qb.where('id', id).where('project_id', projectId)) +} + export const duplicateTemplate = async (template: Template, campaignId: number) => { const params: Partial