Skip to content

Commit

Permalink
better cms email visualization
Browse files Browse the repository at this point in the history
  • Loading branch information
Zwiterrion committed Dec 3, 2024
1 parent d758256 commit 22d2626
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 46 deletions.
15 changes: 14 additions & 1 deletion daikoku/app/controllers/HomeController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,20 @@ class HomeController(
case Some(page) if !page.visible => cmsPageNotFound(ctx)
case Some(page) if page.authenticated && ctx.user.isEmpty =>
redirectToLoginPage(ctx)
case Some(page) => render(ctx, page)
case Some(page) =>
val uri = ctx.request.uri
if (uri.contains("/mails/") && !uri.contains("/mails/root/tenant-mail-template")) {
env.dataStore.cmsRepo.forTenant(ctx.tenant)
.findById("-mails-root-tenant-mail-template-fr")
.flatMap {
case None => render(ctx, page)
case Some(layout) =>
val fields = Map("email" -> JsString(page.body))
render(ctx, layout, skipCache = true, fields = fields)
}
} else {
render(ctx, page)
}
}
}

Expand Down
43 changes: 4 additions & 39 deletions daikoku/javascript/src/components/adminbackoffice/cms/Pages.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import { createColumnHelper } from '@tanstack/react-table';
import classNames from 'classnames';
import moment from 'moment';
import React, { useContext, useEffect, useRef } from 'react';
import { useContext, useEffect, useRef } from 'react';
import { Link, useNavigate } from 'react-router-dom';
import { IPage } from '..';
import { ModalContext } from '../../../contexts';
import { I18nContext } from '../../../contexts';
import * as Services from '../../../services';
import { Table, TableRef } from '../../inputs';

export const CONTENT_TYPES = [
Expand All @@ -20,16 +17,13 @@ export const CONTENT_TYPES = [
];

type PagesProps = {
pages: Array<IPage>,
removePage: (page: string) => void
pages: Array<IPage>
}
export const Pages = ({
pages,
removePage
pages
}: PagesProps) => {
const table = useRef<TableRef>()
const { translate } = useContext(I18nContext);
const { alert, confirm } = useContext(ModalContext);

useEffect(() => {
if (table.current)
Expand Down Expand Up @@ -78,28 +72,18 @@ export const Pages = ({
cell: (info) =>
info.getValue() || <span className="badge bg-dark">{translate('cms.pages.block')}</span>
}),
columnHelper.accessor(row => row.lastPublishedDate ? moment(row.lastPublishedDate).format(translate('moment.date.format')) : '-', {
header: translate('cms.pages.publish_date'),
meta: { style: { textAlign: 'left', width: '200px' } },
enableColumnFilter: false,
}),
columnHelper.display({
header: 'Actions',
meta: { style: { textAlign: 'center', width: '120px' } },
enableColumnFilter: false,
enableSorting: false,
cell: (info) => {
const value = info.row.original;
let isCreatedFromCLI = false;

try {
isCreatedFromCLI = !!JSON.parse(info.row.original.metadata).from
} catch (_) { }

const itemPath = value.path ? (value.path.startsWith('/') ? `/_${value.path}` : `/_/${value.path}`) : '#'

return (
<div className="d-flex align-items-center">
<div className="d-flex align-items-center justify-content-center">
<Link
to={`/settings/pages/${value.id}`}
onClick={(e) => e.stopPropagation()}>
Expand All @@ -118,25 +102,6 @@ export const Pages = ({
<i className="fas fa-eye" />
</button>
</Link>}
{!isCreatedFromCLI && <button
className="btn btn-sm btn-outline-danger"
onClick={(e) => {
e.stopPropagation();
(confirm({ message: translate('cms.pages.remove_confirm') }))
.then((ok) => {
if (ok) {
Services.removeCmsPage(value.id).then((res) => {
if (res.error)
alert({ message: res.error });
else
removePage(value.id);
});
}
});
}}
>
<i className="fas fa-trash" />
</button>}
</div>
);
},
Expand Down
10 changes: 5 additions & 5 deletions daikoku/javascript/src/components/adminbackoffice/cms/index.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { getApolloContext, gql } from '@apollo/client';
import { useContext, useEffect, useRef, useState } from 'react';
import { Route, Routes, useLocation, useNavigate } from 'react-router-dom';
import { useContext, useEffect, useState } from 'react';
import { Route, Routes, useLocation } from 'react-router-dom';
import { I18nContext } from '../../../contexts';
import { Can, manage, tenant } from '../../utils';
import { Create } from './Create';
import { CONTENT_TYPES, Pages } from './Pages';
import { Pages } from './Pages';
import * as Services from '../../../services';
import { Spinner } from '../..';
import { ModalContext, useTenantBackOffice } from '../../../contexts';
import { useTenantBackOffice } from '../../../contexts';

export interface IPage {
id: string
Expand Down Expand Up @@ -86,7 +86,7 @@ export const CMSOffice = () => {
</div>
</div>

<Pages pages={cmsPages} removePage={(id: string) => setPages(cmsPages.filter((f) => f.id !== id))} />
<Pages pages={cmsPages} />
</div>);
};

Expand Down
1 change: 0 additions & 1 deletion daikoku/test/daikoku/suites.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1412,7 +1412,6 @@ object utils {
forwardRef = None,
tags = List(),
metadata = Map(),
draft = "<h1>draft content</h1>",
contentType = "text/html",
body = "<h1>production content</h1>",
path = Some("/" + IdGenerator.token(32))
Expand Down

0 comments on commit 22d2626

Please sign in to comment.