🐛(frontend) draftBody can be null

There was an error in the openapi schema and we are not aware that
message.draftBody could be null so when it was the case, the frontend
throws an error when rendering the `MessageForm` component.
This commit is contained in:
jbpenrath
2025-08-06 10:12:36 +02:00
committed by Jean-Baptiste PENRATH
parent f68925b8bd
commit d0b2a66f08
4 changed files with 5 additions and 3 deletions
+1
View File
@@ -4696,6 +4696,7 @@
},
"draftBody": {
"type": "string",
"nullable": true,
"readOnly": true
},
"attachments": {
+1 -1
View File
@@ -532,7 +532,7 @@ class MessageSerializer(serializers.ModelSerializer):
"""Return the list of HTML body parts (JMAP style)."""
return instance.get_parsed_field("htmlBody") or []
@extend_schema_field(serializers.CharField())
@extend_schema_field(serializers.CharField(allow_null=True))
def get_draftBody(self, instance): # pylint: disable=invalid-name
"""Return an arbitrary JSON object representing the draft body."""
return (
@@ -29,7 +29,8 @@ export interface Message {
readonly updated_at: string;
readonly htmlBody: readonly MessageHtmlBodyItem[];
readonly textBody: readonly MessageTextBodyItem[];
readonly draftBody: string;
/** @nullable */
readonly draftBody: string | null;
readonly attachments: readonly Attachment[];
readonly sender: Contact;
readonly to: readonly Contact[];
@@ -145,7 +145,7 @@ export const MessageForm = ({
}
const formDefaultValues = useMemo(() => {
const [draftBody, draftDriveAttachments] = MailHelper.extractDriveAttachmentsFromDraft(draft?.draftBody);
const [draftBody, draftDriveAttachments] = MailHelper.extractDriveAttachmentsFromDraft(draft?.draftBody ?? '');
return {
from: defaultSenderId ?? '',
to: draft?.to?.map(contact => contact.email) ?? recipients,