Update DebtCard reject button style and refactor email variable extraction

This commit is contained in:
2025-06-08 02:04:57 -03:00
parent 739b3e5ff2
commit 6aa53832dc
3 changed files with 26 additions and 30 deletions

View File

@@ -716,7 +716,7 @@ export function DebtCard({ debt, onUpdate }: DebtCardProps) {
<AlertDialogCancel>Cancel</AlertDialogCancel> <AlertDialogCancel>Cancel</AlertDialogCancel>
<AlertDialogAction <AlertDialogAction
onClick={handleReject} onClick={handleReject}
className="bg-red-600 hover:bg-red-700" className="bg-red-600 hover:bg-red-700 text-white"
> >
Reject Reject
</AlertDialogAction> </AlertDialogAction>

View File

@@ -282,10 +282,10 @@ async function handleNegotiationResponse(
}); });
// Update status to require user review // Update status to require user review
await supabaseAdmin // await supabaseAdmin
.from("debts") // .from("debts")
.update({ status: "requires_manual_review" }) // .update({ status: "awaiting_response" })
.eq("id", debt.id); // .eq("id", debt.id);
return new Response( return new Response(
JSON.stringify({ success: true, message: "Response logged" }), JSON.stringify({ success: true, message: "Response logged" }),

View File

@@ -84,15 +84,15 @@ async function sendEmailViaPostmark(
// Extract variables from text in {{ variable }} format // Extract variables from text in {{ variable }} format
function extractVariables(text: string): string[] { function extractVariables(text: string): string[] {
const variableRegex = /\{\{\s*([^}]+)\s*\}\}/g; const variableRegex = /\{\{([^}]+)\}\}/g;
const matches: string[] = []; const variables: string[] = [];
let match; let match;
while ((match = variableRegex.exec(text)) !== null) { while ((match = variableRegex.exec(text)) !== null) {
if (!matches.includes(match[1].trim())) { variables.push(match[1].trim());
matches.push(match[1].trim());
}
} }
return matches;
return [...new Set(variables)]; // Remove duplicates
} }
// Replace variables in text with their values // Replace variables in text with their values
@@ -100,15 +100,10 @@ function replaceVariables(
text: string, text: string,
variables: Record<string, string>, variables: Record<string, string>,
): string { ): string {
let result = text; return text.replace(/\{\{([^}]+)\}\}/g, (match, variableName) => {
Object.entries(variables).forEach(([key, value]) => { const trimmedName = variableName.trim();
const regex = new RegExp( return variables[trimmedName] || ""; // Replace with empty string if variable not found
`\\{\\{\\s*${key.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}\\s*\\}\\}`,
"g",
);
result = result.replace(regex, value);
}); });
return result;
} }
// Load variables from database for a specific debt // Load variables from database for a specific debt
@@ -329,17 +324,18 @@ Deno.serve(async (req) => {
// Check if there are unfilled variables // Check if there are unfilled variables
if (hasUnfilledVariables) { if (hasUnfilledVariables) {
return new Response( // console.warn("Email contains unfilled variables");
JSON.stringify({ // return new Response(
error: "Email contains unfilled variables", // JSON.stringify({
details: // error: "Email contains unfilled variables",
"Please fill in all required variables before sending the email.", // details:
}), // "Please fill in all required variables before sending the email.",
{ // }),
status: 400, // {
headers: { ...corsHeaders, "Content-Type": "application/json" }, // status: 400,
}, // headers: { ...corsHeaders, "Content-Type": "application/json" },
); // },
// );
} }
const subject = processedSubject; const subject = processedSubject;