Skip to content

Commit 146bf53

Browse files
committed
Add margins and table support in the invitation letter system
1 parent abb524f commit 146bf53

24 files changed

+536
-50
lines changed

backend/api/visa/mutations/update_invitation_letter_document.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,23 @@ class UpdateInvitationLetterDocumentPageInput:
1515
content: str
1616

1717

18+
@strawberry.input
19+
class UpdateInvitationLetterDocumentRunningPartInput:
20+
content: str
21+
align: str
22+
margin: str
23+
24+
25+
@strawberry.input
26+
class UpdateInvitationLetterDocumentPageLayoutInput:
27+
margin: str
28+
29+
1830
@strawberry.input
1931
class UpdateInvitationLetterDocumentStructureInput:
20-
header: str
21-
footer: str
32+
header: UpdateInvitationLetterDocumentRunningPartInput
33+
footer: UpdateInvitationLetterDocumentRunningPartInput
34+
page_layout: UpdateInvitationLetterDocumentPageLayoutInput
2235
pages: list[UpdateInvitationLetterDocumentPageInput]
2336

2437

@@ -29,12 +42,12 @@ class UpdateInvitationLetterDocumentInput:
2942

3043

3144
@strawberry.type
32-
class InvitationLetterNotEditable:
45+
class InvitationLetterDocumentNotEditable:
3346
message: str = "Invitation letter document is not editable"
3447

3548

3649
UpdateInvitationLetterDocumentResult = Annotated[
37-
InvitationLetterDocument | InvitationLetterNotEditable | NotFound,
50+
InvitationLetterDocument | InvitationLetterDocumentNotEditable | NotFound,
3851
strawberry.union(name="UpdateInvitationLetterDocumentResult"),
3952
]
4053

@@ -51,7 +64,7 @@ def update_invitation_letter_document(
5164
return NotFound()
5265

5366
if invitation_letter_document.document:
54-
return InvitationLetterNotEditable()
67+
return InvitationLetterDocumentNotEditable()
5568

5669
invitation_letter_document.dynamic_document = strawberry.asdict(
5770
input.dynamic_document

backend/api/visa/tests/mutations/test_update_invitation_letter_document.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def test_cannot_update_invitation_letter_document_with_static_doc(
118118

119119
assert (
120120
response["data"]["updateInvitationLetterDocument"]["__typename"]
121-
== "InvitationLetterNotEditable"
121+
== "InvitationLetterDocumentNotEditable"
122122
)
123123
document.refresh_from_db()
124124
assert document.dynamic_document is None

backend/api/visa/types.py

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,51 @@ def from_object(cls, obj: dict):
5454
)
5555

5656

57+
@strawberry.type
58+
class InvitationLetterDocumentRunningPart:
59+
content: str
60+
align: str
61+
margin: str
62+
63+
@classmethod
64+
def from_object(cls, obj: dict):
65+
return cls(
66+
content=obj.get("content", ""),
67+
align=obj.get("align", ""),
68+
margin=obj.get("margin", ""),
69+
)
70+
71+
72+
@strawberry.type
73+
class InvitationLetterDocumentPageLayout:
74+
margin: str
75+
76+
@classmethod
77+
def from_object(cls, obj: dict):
78+
return cls(
79+
margin=obj.get("margin", ""),
80+
)
81+
82+
5783
@strawberry.type
5884
class InvitationLetterDocumentStructure:
59-
header: str
60-
footer: str
85+
header: InvitationLetterDocumentRunningPart
86+
footer: InvitationLetterDocumentRunningPart
87+
page_layout: InvitationLetterDocumentPageLayout
6188
pages: list[InvitationLetterDocumentPage]
6289

6390
@classmethod
6491
def from_object(cls, obj: dict):
6592
return cls(
66-
header=obj.get("header", ""),
67-
footer=obj.get("footer", ""),
93+
header=InvitationLetterDocumentRunningPart.from_object(
94+
obj.get("header", {})
95+
),
96+
footer=InvitationLetterDocumentRunningPart.from_object(
97+
obj.get("footer", {})
98+
),
99+
page_layout=InvitationLetterDocumentPageLayout.from_object(
100+
obj.get("page_layout", {})
101+
),
68102
pages=[
69103
InvitationLetterDocumentPage.from_object(page)
70104
for page in obj.get("pages", [])

backend/custom_admin/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131
"@tiptap/extension-link": "^2.10.4",
3232
"@tiptap/extension-list-item": "^2.10.3",
3333
"@tiptap/extension-placeholder": "^2.10.4",
34+
"@tiptap/extension-table": "^2.11.0",
35+
"@tiptap/extension-table-cell": "^2.11.0",
36+
"@tiptap/extension-table-header": "^2.11.0",
37+
"@tiptap/extension-table-row": "^2.11.0",
3438
"@tiptap/extension-text-align": "^2.10.3",
3539
"@tiptap/extension-text-style": "^2.10.3",
3640
"@tiptap/extension-underline": "^2.10.4",

backend/custom_admin/pnpm-lock.yaml

Lines changed: 50 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { Fragment, useEffect } from "react";
55

66
import { EditorSection } from "./editor-section";
77
import { useLocalData } from "./local-state";
8+
import { PageLayoutOptions } from "./page-layout-option";
89

910
export const InvitationLetterBuilder = () => {
1011
const { isDirty, localData, saveChanges, isSaving, addPage } = useLocalData();
@@ -37,33 +38,25 @@ export const InvitationLetterBuilder = () => {
3738

3839
<Box height="var(--space-5)" />
3940

40-
<EditorSection
41-
title="Header"
42-
content={localData.header}
43-
pageId="header"
44-
/>
41+
<EditorSection title="Header" pageId="header" />
4542
<Box height="var(--space-5)" />
4643

47-
<EditorSection
48-
title="Footer"
49-
content={localData.footer}
50-
pageId="footer"
51-
/>
44+
<EditorSection title="Footer" pageId="footer" />
5245
</Card>
5346

5447
<Box height="var(--space-5)" />
5548

5649
<Card>
5750
<Heading>Pages</Heading>
51+
<Box height="var(--space-1)" />
52+
53+
<PageLayoutOptions />
54+
5855
<Box height="var(--space-5)" />
5956

6057
{localData.pages.map((page) => (
6158
<Fragment key={page.id}>
62-
<EditorSection
63-
title={page.title}
64-
content={page.content}
65-
pageId={page.id}
66-
/>
59+
<EditorSection title={page.title} pageId={page.id} />
6760
<Box height="var(--space-3)" />
6861
</Fragment>
6962
))}

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ import {
33
Button,
44
Dialog,
55
Flex,
6+
Grid,
67
Heading,
8+
RadioGroup,
79
Text,
810
TextField,
911
Theme,
@@ -13,18 +15,23 @@ import { MoveDown, MoveUp, Pencil, Trash } from "lucide-react";
1315
import { RichEditor } from "../shared/rich-editor";
1416
import { HideNode } from "../shared/rich-editor/menu-bar";
1517
import { useLocalData } from "./local-state";
18+
import { RunningElementsOptions } from "./running-elements-options";
1619

1720
export const EditorSection = ({
1821
title,
19-
content,
2022
pageId,
2123
}: {
2224
title: string;
23-
content: string;
2425
pageId: string;
2526
}) => {
26-
const { movePageUp, movePageDown, removePage, renamePage, setContent } =
27-
useLocalData();
27+
const {
28+
movePageUp,
29+
movePageDown,
30+
removePage,
31+
renamePage,
32+
setContent,
33+
getContent,
34+
} = useLocalData();
2835
const isPage = pageId !== "header" && pageId !== "footer";
2936

3037
const onMoveUp = () => movePageUp(pageId);
@@ -33,6 +40,8 @@ export const EditorSection = ({
3340
const onRename = (value: string) => renamePage(pageId, value);
3441
const onUpdate = (content: string) => setContent(pageId, content);
3542

43+
const content = getContent(pageId);
44+
3645
return (
3746
<Box>
3847
<Flex align="center" gap="3">
@@ -50,6 +59,7 @@ export const EditorSection = ({
5059
)}
5160
{isPage && <RemovePage onRemove={onRemove} />}
5261
</Flex>
62+
{!isPage && <RunningElementsOptions pageId={pageId} />}
5363
<Box height="var(--space-3)" />
5464
<RichEditor
5565
hide={[HideNode.buttonNode, HideNode.link]}

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,19 @@ query InvitationLetterDocument($id: ID!) {
22
invitationLetterDocument(id: $id) {
33
id
44
dynamicDocument {
5-
header
6-
footer
5+
header {
6+
content
7+
align
8+
margin
9+
}
10+
footer {
11+
content
12+
align
13+
margin
14+
}
15+
pageLayout {
16+
margin
17+
}
718
pages {
819
id
920
title

0 commit comments

Comments
 (0)