@bygghammar/cms-platform 0.26.0 → 0.28.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +23 -0
- package/package.json +6 -3
- package/src/backoffice/FormDeliveriesView.tsx +344 -0
- package/src/backoffice/FormSettingsView.tsx +436 -0
- package/src/backoffice/FormSubmissionsView.tsx +646 -0
- package/src/backoffice/SiteSettingsView.tsx +28 -7
- package/src/config/site-config.ts +22 -0
|
@@ -18,6 +18,11 @@ export type SiteSettingsDeps = {
|
|
|
18
18
|
saveSettings: (input: { data: SiteSettingOverrides }) => Promise<unknown>;
|
|
19
19
|
clearSetting: (input: { data: { key: string } }) => Promise<unknown>;
|
|
20
20
|
refresh: () => Promise<unknown> | void;
|
|
21
|
+
/**
|
|
22
|
+
* Where the running public origin came from. `"environment"` means the host
|
|
23
|
+
* set `SITE_URL` for this deployment; `"code"` means the compiled fallback.
|
|
24
|
+
*/
|
|
25
|
+
originSource?: "environment" | "code";
|
|
21
26
|
};
|
|
22
27
|
|
|
23
28
|
const FEATURE_LABELS: Record<keyof SiteFeatureFlags, string> = {
|
|
@@ -54,6 +59,7 @@ const cardClass = "border border-ink/10 bg-white p-6";
|
|
|
54
59
|
*/
|
|
55
60
|
export function SiteSettingsView({ deps }: { deps: SiteSettingsDeps }) {
|
|
56
61
|
const { config, overrides, saveSettings, clearSetting, refresh } = deps;
|
|
62
|
+
const originSource = deps.originSource ?? "code";
|
|
57
63
|
const [name, setName] = useState(config.name);
|
|
58
64
|
const [company, setCompany] = useState({ ...EMPTY_COMPANY, ...config.company });
|
|
59
65
|
const [features, setFeatures] = useState<SiteFeatureFlags>({ ...config.features });
|
|
@@ -99,23 +105,38 @@ export function SiteSettingsView({ deps }: { deps: SiteSettingsDeps }) {
|
|
|
99
105
|
<div className="p-8 md:p-12 w-full">
|
|
100
106
|
<h1 className="font-serif text-3xl md:text-4xl text-ink">Site settings</h1>
|
|
101
107
|
<p className="mt-3 max-w-2xl text-sm text-ink/60">
|
|
102
|
-
|
|
103
|
-
an override in the database and can be reset back to the code default.
|
|
108
|
+
Site name, company details, brand colours and modules are editable here — a change is stored
|
|
109
|
+
as an override in the database and can be reset back to the code default. The fields below
|
|
110
|
+
are set outside the backoffice and shown for reference only.
|
|
104
111
|
</p>
|
|
105
112
|
|
|
106
113
|
<dl className="mt-8 grid gap-4 md:grid-cols-4">
|
|
107
114
|
{[
|
|
108
|
-
["Site key", config.key],
|
|
109
|
-
[
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
115
|
+
["Site key", config.key, "Set in code"],
|
|
116
|
+
[
|
|
117
|
+
"Public origin",
|
|
118
|
+
config.origin,
|
|
119
|
+
originSource === "environment" ? "From SITE_URL" : "Code fallback \u2014 SITE_URL unset",
|
|
120
|
+
],
|
|
121
|
+
["Locales", config.locales.join(", "), "Set in code"],
|
|
122
|
+
[
|
|
123
|
+
"Backoffice",
|
|
124
|
+
`${config.backofficePath} (${config.backofficeLocale})`,
|
|
125
|
+
"Set in code",
|
|
126
|
+
],
|
|
127
|
+
].map(([label, value, source]) => (
|
|
113
128
|
<div key={label} className="border border-ink/10 bg-white p-4">
|
|
114
129
|
<dt className="text-xs uppercase tracking-wider text-ink/50">{label}</dt>
|
|
115
130
|
<dd className="mt-1 text-sm text-ink">{value}</dd>
|
|
131
|
+
<dd className="mt-2 text-[11px] uppercase tracking-wider text-ink/40">{source}</dd>
|
|
116
132
|
</div>
|
|
117
133
|
))}
|
|
118
134
|
</dl>
|
|
135
|
+
<p className="mt-3 max-w-2xl text-xs text-ink/50">
|
|
136
|
+
These four are structural: the locale set and backoffice path are compiled into the build,
|
|
137
|
+
and the public origin differs per environment. They are read from code and environment on
|
|
138
|
+
purpose, so a deployment can never disagree with what the database says.
|
|
139
|
+
</p>
|
|
119
140
|
|
|
120
141
|
<section className={`mt-8 ${cardClass}`}>
|
|
121
142
|
<SectionHeader
|
|
@@ -140,6 +140,28 @@ export function defineSiteConfig(input: SiteConfigInput): SiteConfig {
|
|
|
140
140
|
};
|
|
141
141
|
}
|
|
142
142
|
|
|
143
|
+
/**
|
|
144
|
+
* Resolve the canonical public origin for this deployment.
|
|
145
|
+
*
|
|
146
|
+
* The origin is a deployment fact, not editable content: preview, staging and
|
|
147
|
+
* production all differ, so it comes from the environment (`SITE_URL`) and only
|
|
148
|
+
* falls back to the value compiled into `site.config.ts`. It is deliberately
|
|
149
|
+
* never stored in the database — canonical URLs, sitemaps and auth redirects
|
|
150
|
+
* must be correct before any database read.
|
|
151
|
+
*/
|
|
152
|
+
export function resolveSiteOrigin(fallback: string, rawEnvValue?: string | null): string {
|
|
153
|
+
const raw = (rawEnvValue ?? "").trim().replace(/\/+$/, "");
|
|
154
|
+
if (!raw) return fallback.replace(/\/$/, "");
|
|
155
|
+
const withScheme = /^https?:\/\//i.test(raw) ? raw : `https://${raw}`;
|
|
156
|
+
// Anything malformed is ignored rather than breaking every canonical URL.
|
|
157
|
+
return /^https?:\/\/[^/]+$/.test(withScheme) ? withScheme : fallback.replace(/\/$/, "");
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** True when the running origin came from the environment, not from code. */
|
|
161
|
+
export function originIsFromEnvironment(fallback: string, rawEnvValue?: string | null): boolean {
|
|
162
|
+
return resolveSiteOrigin(fallback, rawEnvValue) !== fallback.replace(/\/$/, "");
|
|
163
|
+
}
|
|
164
|
+
|
|
143
165
|
/**
|
|
144
166
|
* Keys the backoffice may override from the database. Everything else is
|
|
145
167
|
* code-only on purpose: routing, locale set and origin must be deployable and
|