fix: 5 issues - leads 500, prepaid amount/invoice, install RESOLVED, dup tickets, confirm fail

This commit is contained in:
Nemo
2026-03-24 14:52:40 +08:00
parent 16cf1c0616
commit 882e416a40
3 changed files with 40 additions and 32 deletions

View File

@@ -151,25 +151,26 @@ export default function NewClientScreen() {
startDate: new Date().toISOString(),
});
// 3. Create installation ticket
const ticketRes = await api.post('/api/v1/tickets', {
clientId: client.id,
subject: `New Installation — ${firstName.trim()} ${lastName.trim()}`,
type: 'INSTALLATION',
priority: 'NORMAL',
// Pass subType so activation ticket knows to gate on payment for PREPAID
...(subType === 'PREPAID' ? { priority: 'HIGH' } : {}),
});
const ticket = ticketRes.data;
// 3. Fetch the auto-created installation ticket (API creates one on client creation)
let ticket: any = null;
try {
const ticketsRes = await api.get(`/api/v1/tickets?clientId=${client.id}&type=INSTALLATION&limit=1`);
const items = ticketsRes.data?.data ?? ticketsRes.data ?? [];
ticket = items[0] ?? null;
} catch {}
Alert.alert(
'Client Onboarded! 🎉',
`${firstName} ${lastName} has been registered.\n\nAn installation ticket has been created.`,
[{
text: 'View Ticket',
text: ticket ? 'View Ticket' : 'View Client',
onPress: () => {
router.replace('/(app)/clients');
setTimeout(() => router.push(`/(app)/tasks/${ticket.id}`), 300);
if (ticket) {
router.replace('/(app)/clients');
setTimeout(() => router.push(`/(app)/tasks/${ticket.id}`), 300);
} else {
router.replace('/(app)/clients');
}
},
}, {
text: 'Done',