Files
mdb/mdb-predator/src/services/offerPdf.ts
Bastien COIGNOUX bd325fe456 init
2026-05-03 20:18:33 +02:00

33 lines
1.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import * as Print from 'expo-print';
import * as Sharing from 'expo-sharing';
import { Platform } from 'react-native';
export async function sharePurchaseOfferPdf(params: {
propertyTitle: string;
address: string;
maxBuyPriceEur: number;
sellerName?: string;
}): Promise<void> {
const html = `<!DOCTYPE html><html lang="fr"><head><meta charset="utf-8"/>
<style>body{font-family:system-ui;padding:32px;color:#111}
h1{font-size:22px} .box{border:1px solid #ccc;padding:16px;border-radius:8px;margin-top:16px}
</style></head><body>
<h1>Offre d'achat — ${escape(params.propertyTitle)}</h1>
<p>${escape(params.address)}</p>
<div class="box">
<p>Montant de l'offre : <strong>${params.maxBuyPriceEur.toLocaleString('fr-FR')} €</strong></p>
<p>(${params.sellerName ? `Destinataire : ${escape(params.sellerName)}` : 'À compléter'})</p>
</div>
<p style="margin-top:24px;font-size:11px;color:#666">MDB-PREDATOR — modèle indicatif, valider avec votre notaire / juriste.</p>
</body></html>`;
const { uri } = await Print.printToFileAsync({ html });
if (Platform.OS === 'web') return;
if (await Sharing.isAvailableAsync()) {
await Sharing.shareAsync(uri, { mimeType: 'application/pdf', dialogTitle: 'Offre dachat' });
}
}
function escape(s: string): string {
return s.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/"/g, '&quot;');
}