File size: 1,837 Bytes
c09f67c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | // Define a generic customer interface to avoid circular dependencies
interface CustomerData {
name?: string | null;
addressLine1?: string | null;
addressLine2?: string | null;
city?: string | null;
zip?: string | null;
country?: string | null;
email?: string | null;
phone?: string | null;
website?: string | null;
vatNumber?: string | null;
}
export const transformCustomerToContent = (customer?: CustomerData | null) => {
if (!customer) return null;
const content = [];
if (customer.name) {
content.push({
type: "paragraph",
content: [
{
text: customer.name,
type: "text",
},
],
});
}
if (customer.addressLine1) {
content.push({
type: "paragraph",
content: [{ text: customer.addressLine1, type: "text" }],
});
}
if (customer.addressLine2) {
content.push({
type: "paragraph",
content: [{ text: customer.addressLine2, type: "text" }],
});
}
if (customer.zip || customer.city) {
content.push({
type: "paragraph",
content: [
{
text: `${customer.zip || ""} ${customer.city || ""}`.trim(),
type: "text",
},
],
});
}
if (customer.country) {
content.push({
type: "paragraph",
content: [{ text: customer.country, type: "text" }],
});
}
if (customer.email) {
content.push({
type: "paragraph",
content: [{ text: customer.email, type: "text" }],
});
}
if (customer.phone) {
content.push({
type: "paragraph",
content: [{ text: customer.phone, type: "text" }],
});
}
if (customer.vatNumber) {
content.push({
type: "paragraph",
content: [{ text: customer.vatNumber, type: "text" }],
});
}
return {
type: "doc",
content,
};
};
|