init
This commit is contained in:
32
mdb-predator/src/services/offerPdf.ts
Normal file
32
mdb-predator/src/services/offerPdf.ts
Normal file
@ -0,0 +1,32 @@
|
||||
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 d’achat' });
|
||||
}
|
||||
}
|
||||
|
||||
function escape(s: string): string {
|
||||
return s.replace(/&/g, '&').replace(/</g, '<').replace(/"/g, '"');
|
||||
}
|
||||
Reference in New Issue
Block a user