From aef712b409d0574d90e1ac41a56601da8f68ac57 Mon Sep 17 00:00:00 2001 From: Thanaphon Frappet Date: Wed, 27 Nov 2024 12:55:38 +0700 Subject: [PATCH] fix: function convertTemplate --- src/utils/string-template.ts | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/utils/string-template.ts b/src/utils/string-template.ts index 5858a844..752ef3e3 100644 --- a/src/utils/string-template.ts +++ b/src/utils/string-template.ts @@ -4,12 +4,31 @@ const templates = { return context?.join(', ') || ''; }, }, + 'quotation-payment': { + converter: (context?: { + paymentType: 'full' | 'installments'; + installments: { + date: string; + amount: number; + }[]; + }) => { + return ( + context?.installments + .map( + (v) => + `asdasd + `, + ) + .join(', ') || '' + ); + }, + }, } as const; type Template = typeof templates; type TemplateName = keyof Template; type TemplateContext = { - [key in TemplateName]: Parameters[0]; + [key in TemplateName]: Parameters[0]; }; export function convertTemplate( @@ -25,7 +44,7 @@ export function convertTemplate( ret = text.replace( new RegExp('\\#\\[' + name.replaceAll('-', '\\-') + '\\]', 'g'), typeof template.converter === 'function' - ? template.converter(context?.[name as TemplateName]) + ? template.converter(context?.[name as TemplateName] as any) : template.converter, ); }