Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions apps/trustlab/src/next-seo.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ const config = {
openGraph: {
type: "website",
locale: "en_GB",
url: site.environmentUrl,
url: site.url,
site_name: site.name,
images: [
{
url: `${site.environmentUrl}image.jpg`,
url: `${site.url}image.jpg`,
width: 1600,
height: 800,
alt: site.name,
Expand Down
3 changes: 2 additions & 1 deletion apps/trustlab/src/payload/access/abilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ export const canManageContent = (user) => {
export const canManagePages = (user) =>
checkRole([ROLE_ADMIN, ROLE_EDITOR], user);

export const canManageSiteSettings = (user) => checkRole([ROLE_ADMIN], user);
export const canManageSiteSettings = ({ req: { user } }) =>
checkRole([ROLE_ADMIN], user);

// TODO(@kelvinkipruto): what happens on delete? cascade or not?
export const canManageUsers = (user) => {
Expand Down
2 changes: 2 additions & 0 deletions apps/trustlab/src/payload/access/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./anyone";
export * from "./loggedIn";
3 changes: 2 additions & 1 deletion apps/trustlab/src/payload/collections/Media.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { createdBy } from "@commons-ui/payload";

import { canManageContent } from "@/trustlab/payload/access/abilities";
import { anyone } from "@/trustlab/payload/access/anyone";
import { hideAPIURL } from "@/trustlab/payload/utils";

const filename = fileURLToPath(import.meta.url);
const dirname = path.dirname(filename);
Expand All @@ -19,7 +20,7 @@ const Media = {
},
admin: {
group: "Publication",
hideAPIURL: true,
hideAPIURL,
},
fields: [
{
Expand Down
7 changes: 5 additions & 2 deletions apps/trustlab/src/payload/collections/Pages.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { slug, fullTitle } from "@commons-ui/payload";
import { canManagePages } from "@/trustlab/payload/access/abilities";
import { anyone } from "@/trustlab/payload/access/anyone";
import TestBlock from "@/trustlab/payload/blocks/TestBlock";
import { hideAPIURL } from "@/trustlab/payload/utils";

const Pages = {
slug: "pages",
Expand All @@ -16,7 +17,7 @@ const Pages = {
defaultColumns: ["fullTitle", "updatedAt", "_status"],
group: "Publication",
useAsTitle: "title",
hideAPIURL: true,
hideAPIURL,
preview: ({ slug: pageSlug }) => {
const encodedParams = new URLSearchParams({
slug: pageSlug,
Expand Down Expand Up @@ -47,7 +48,9 @@ const Pages = {
},
],
versions: {
drafts: true,
drafts: {
autosave: true,
},
},
};

Expand Down
3 changes: 2 additions & 1 deletion apps/trustlab/src/payload/collections/Posts.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { slug, createdBy } from "@commons-ui/payload";

import { canManageContent } from "@/trustlab/payload/access/abilities";
import { anyone } from "@/trustlab/payload/access/anyone";
import { hideAPIURL } from "@/trustlab/payload/utils";

const Posts = {
slug: "posts",
Expand All @@ -15,7 +16,7 @@ const Posts = {
defaultColumns: ["title", "createdBy", "updatedAt", "_status"],
group: "Publication",
useAsTitle: "title",
hideAPIURL: true,
hideAPIURL,
preview: ({ slug: pageSlug }) => {
const encodedParams = new URLSearchParams({
slug: pageSlug,
Expand Down
11 changes: 7 additions & 4 deletions apps/trustlab/src/payload/globals/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,22 @@ import EngagementTab from "./tabs/EngagementTab";
import GeneralTab from "./tabs/GeneralTab";
import NavigationTab from "./tabs/NavigationTab";

import { loggedIn } from "@/trustlab/payload/access";
import { canManageSiteSettings } from "@/trustlab/payload/access/abilities";
import { anyone } from "@/trustlab/payload/access/anyone";
import { hideAPIURL } from "@/trustlab/payload/utils";

const SiteSettings = {
slug: "site-settings",
label: "Site",
admin: {
group: "Settings",
hideAPIURL: true,
hideAPIURL,
},
access: {
read: anyone,
update: ({ req: { user } }) => canManageSiteSettings(user),
// Since we're using Local APIs, we should still be able to pull data server-side
// See: note in https://payloadcms.com/docs/local-api/overview#transactions
read: loggedIn,
update: canManageSiteSettings,
},
fields: [
{
Expand Down
5 changes: 3 additions & 2 deletions apps/trustlab/src/payload/globals/tabs/EngagementTab.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ const EngagementTab = {
name: "connect",
type: "group",
label: "Social Accounts",
// If localized is enabled at group level, no need for localized at nested field level
// https://payloadcms.com/docs/fields/group
localized: true,
fields: [
{
Expand All @@ -21,7 +23,6 @@ const EngagementTab = {
"Text that appears on contact links e.g Stay in Touch",
},
required: true,
localized: true,
},
socialLinks(),
],
Expand All @@ -32,6 +33,7 @@ const EngagementTab = {
name: "newsletter",
type: "group",
label: "Email Newsletter",
localized: true,
fields: [
{
type: "collapsible",
Expand All @@ -41,7 +43,6 @@ const EngagementTab = {
name: "title",
type: "text",
required: true,
localized: true,
},
{
name: "embedCode",
Expand Down
5 changes: 5 additions & 0 deletions apps/trustlab/src/payload/utils/hideAPIURL.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { site } from "@/trustlab/utils";

const hideAPIURL = site.environment === "production";

export default hideAPIURL;
3 changes: 3 additions & 0 deletions apps/trustlab/src/payload/utils/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export { default as hideAPIURL } from "./hideAPIURL";

export default undefined;
3 changes: 3 additions & 0 deletions apps/trustlab/src/utils/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export { default as site } from "./site";

export default undefined;
12 changes: 4 additions & 8 deletions apps/trustlab/src/utils/site.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
const environment = (process.env.SENTRY_ENVIRONMENT ?? "local")
.trim()
.toLowerCase();
const name = process.env.NEXT_PUBLIC_APP_NAME ?? "TrustLab";

// see: https://developer.mozilla.org/en-US/docs/Web/API/URL/pathname
Expand All @@ -9,18 +12,11 @@ const ensureTrailingSlash = (string) => {
return url.toString();
};
const url = ensureTrailingSlash(process.env.NEXT_PUBLIC_APP_URL);
let environmentUrl = url;
if (process.env.NEXT_PUBLIC_VERCEL_ENV === "preview") {
environmentUrl = ensureTrailingSlash(
`https://${process.env.NEXT_PUBLIC_VERCEL_URL}`,
);
}

const site = {
environmentUrl,
environment,
name,
url,
logoUrl: process.env.NEXT_PUBLIC_APP_LOGO_URL,
};

export default site;
5 changes: 3 additions & 2 deletions apps/trustlab/turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
"env": [
"NEXT_RUNTIME",
"PREVIEW_SECRET",
"S3_ACCESS_KEY_ID",
"S3_BUCKET",
"S3_REGION",
"S3_ACCESS_KEY_ID",
"S3_SECRET_ACCESS_KEY"
"S3_SECRET_ACCESS_KEY",
"SENTRY_ENVIRONMENT"
]
}
}
Expand Down
Loading