Skip to content

Commit 4dd05ee

Browse files
committed
more cleannup
1 parent 5baaa67 commit 4dd05ee

File tree

6 files changed

+48
-40
lines changed

6 files changed

+48
-40
lines changed

backend/custom_admin/src/components/invitation-letter-document-builder/builder.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Button } from "@radix-ui/themes";
22
import { Box } from "@radix-ui/themes";
33
import { useEffect } from "react";
44

5+
import { Spacer } from "../shared/spacer";
56
import { DocumentSettings } from "./document-settings";
67
import { useLocalData } from "./local-state";
78
import { Pages } from "./pages";
@@ -28,15 +29,16 @@ export const InvitationLetterBuilder = () => {
2829

2930
return (
3031
<>
31-
<Box height="var(--space-3)" />
32+
<Spacer />
3233

3334
<DocumentSettings />
3435

35-
<Box height="var(--space-5)" />
36+
<Spacer size={5} />
3637

3738
<Pages />
3839

39-
<Box height="var(--space-3)" />
40+
<Spacer />
41+
4042
<Box position="sticky" bottom="0" p="3" className="bg-white">
4143
<Button onClick={saveChanges} loading={isSaving}>
4244
Save changes

backend/custom_admin/src/components/invitation-letter-document-builder/document-settings.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1-
import { Box, Button, Card, Heading, Text } from "@radix-ui/themes";
1+
import { Card, Heading, Text } from "@radix-ui/themes";
2+
import { Spacer } from "../shared/spacer";
23
import { EditorSection } from "./editor-section";
34

45
export const DocumentSettings = () => {
56
return (
67
<Card>
78
<Heading as="h1">Document</Heading>
8-
<Box height="var(--space-2)" />
9+
<Spacer />
10+
911
<Text>Header and footer are shared across all pages.</Text>
1012

11-
<Box height="var(--space-5)" />
13+
<Spacer size={5} />
1214

1315
<EditorSection title="Header" pageId="header" />
14-
<Box height="var(--space-5)" />
16+
<Spacer size={5} />
1517

1618
<EditorSection title="Footer" pageId="footer" />
1719
</Card>

backend/custom_admin/src/components/invitation-letter-document-builder/editor-section.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { Box } from "@radix-ui/themes";
1111
import { MoveDown, MoveUp, Pencil, Trash } from "lucide-react";
1212
import { RichEditor } from "../shared/rich-editor";
1313
import { HideNode } from "../shared/rich-editor/menu-bar";
14+
import { Spacer } from "../shared/spacer";
1415
import { useLocalData } from "./local-state";
1516
import { RunningElementsOptions } from "./running-elements-options";
1617

@@ -57,7 +58,9 @@ export const EditorSection = ({
5758
{isPage && <RemovePage onRemove={onRemove} />}
5859
</Flex>
5960
{!isPage && <RunningElementsOptions pageId={pageId} />}
60-
<Box height="var(--space-3)" />
61+
62+
<Spacer size={3} />
63+
6164
<RichEditor
6265
hide={[HideNode.buttonNode, HideNode.link]}
6366
content={content}

backend/custom_admin/src/components/invitation-letter-document-builder/local-state.tsx

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,8 @@ export const LocalStateProvider = ({ children }) => {
291291
const isDirty = !equal(remoteData, localData);
292292
const data = localData || remoteData;
293293

294+
const findPage = (pageId) => data.pages.find((page) => page.id === pageId);
295+
294296
return (
295297
<LocalStateContext
296298
value={{
@@ -301,65 +303,55 @@ export const LocalStateProvider = ({ children }) => {
301303
return data[pageId].content;
302304
}
303305

304-
return data.pages.find((page) => page.id === pageId).content;
306+
return findPage(pageId).content;
305307
},
306308
getProperties: (pageId) => {
307309
if (pageId === "header" || pageId === "footer") {
308310
return data[pageId];
309311
}
310312

311-
const page = data.pages.find((page) => page.id === pageId);
312-
return page;
313-
},
314-
getPageLayout: () => {
315-
return data.pageLayout;
313+
return findPage(pageId);
316314
},
317-
setPageLayoutProperty: (property, value) => {
315+
getPageLayout: () => data.pageLayout,
316+
setPageLayoutProperty: (property, value) =>
318317
dispatch({
319318
type: ActionType.SetPageLayoutProperty,
320319
payload: { property, value },
321-
});
322-
},
320+
}),
323321
saveChanges: () => saveChanges(localData),
324-
setProperty: (pageId, property, value) => {
322+
setProperty: (pageId, property, value) =>
325323
dispatch({
326324
type: ActionType.SetProperty,
327325
payload: { pageId, property, value },
328-
});
329-
},
326+
}),
330327
isSaving,
331328
saveFailed,
332329
addPage: () => dispatch({ type: ActionType.AddPage }),
333-
renamePage: (pageId, title) => {
330+
renamePage: (pageId, title) =>
334331
dispatch({
335332
type: ActionType.RenamePage,
336333
payload: { pageId, title },
337-
});
338-
},
339-
setContent: (pageId, content) => {
334+
}),
335+
setContent: (pageId, content) =>
340336
dispatch({
341337
type: ActionType.SetContent,
342338
payload: { pageId, content },
343-
});
344-
},
345-
removePage: (pageId) => {
339+
}),
340+
removePage: (pageId) =>
346341
dispatch({
347342
type: ActionType.RemovePage,
348343
payload: { pageId },
349-
});
350-
},
351-
movePageUp: (pageId) => {
344+
}),
345+
movePageUp: (pageId) =>
352346
dispatch({
353347
type: ActionType.MovePageUp,
354348
payload: { pageId },
355-
});
356-
},
357-
movePageDown: (pageId) => {
349+
}),
350+
movePageDown: (pageId) =>
358351
dispatch({
359352
type: ActionType.MovePageDown,
360353
payload: { pageId },
361-
});
362-
},
354+
}),
363355
}}
364356
>
365357
{children}

backend/custom_admin/src/components/invitation-letter-document-builder/pages.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { Button, Card, Heading } from "@radix-ui/themes";
2-
import { Box } from "@radix-ui/themes";
32
import { Plus } from "lucide-react";
43

54
import { Fragment } from "react";
5+
import { Spacer } from "../shared/spacer";
66
import { EditorSection } from "./editor-section";
77
import { useLocalData } from "./local-state";
88
import { PageLayoutOptions } from "./page-layout-option";
@@ -14,20 +14,22 @@ export const Pages = () => {
1414
return (
1515
<Card>
1616
<Heading>Pages</Heading>
17-
<Box height="var(--space-1)" />
17+
18+
<Spacer size={1} />
1819

1920
<PageLayoutOptions />
2021

21-
<Box height="var(--space-5)" />
22+
<Spacer size={5} />
2223

2324
{pages.map((page) => (
2425
<Fragment key={page.id}>
2526
<EditorSection title={page.title} pageId={page.id} />
26-
<Box height="var(--space-3)" />
27+
<Spacer />
2728
</Fragment>
2829
))}
2930

30-
<Box height="var(--space-2)" />
31+
<Spacer size={2} />
32+
3133
<Button variant="soft" onClick={addPage}>
3234
<Plus size={16} />
3335
Add Page
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { Box } from "@radix-ui/themes";
2+
3+
export const Spacer = ({
4+
size = 3,
5+
}: {
6+
size?: number;
7+
}) => <Box height={`var(--space-${size})`} />;

0 commit comments

Comments
 (0)