diff --git a/src/pages/transaction/history-transaction/blocks/DetailTransaction.tsx b/src/pages/transaction/history-transaction/blocks/DetailTransaction.tsx index 0d8dc59..38dfbb2 100644 --- a/src/pages/transaction/history-transaction/blocks/DetailTransaction.tsx +++ b/src/pages/transaction/history-transaction/blocks/DetailTransaction.tsx @@ -49,7 +49,6 @@ const DetailTransaction = () => { id: selectedTransactionId }); setTransactionDetails(response?.data); - // console.log(response?.data); // console.log(selectedTransactionId); } catch (error) { console.error('Error fetching transaction', error); @@ -156,6 +155,35 @@ const DetailTransaction = () => { }); } + const [formattedJson, setFormattedJson] = useState(''); + const [highlightedJson, setHighlightedJson] = useState(''); + + useEffect(() => { + const obj = { a: 1, 'b': 'foo', c: [false, 'false', null, 'null', { d: { e: 1.3e5, f: '1.3e5' } }] }; + const str = JSON.stringify(obj, undefined, 4); + setFormattedJson(str); + setHighlightedJson(syntaxHighlight(str)); + }, []); + + function syntaxHighlight(json: any) { + json = json.replace(/&/g, '&').replace(//g, '>'); + return json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])"(\s:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, function (match: any) { + let cls = 'number'; + if (/^"/.test(match)) { + if (/:$/.test(match)) { + cls = 'key'; + } else { + cls = 'string'; + } + } else if (/true|false/.test(match)) { + cls = 'boolean'; + } else if (/null/.test(match)) { + cls = 'null'; + } + return '' + match + ''; + }); + } + return ( @@ -202,6 +230,15 @@ const DetailTransaction = () => { )} + {transactionDetails?.kind !== 'P' && ( + + )} + )} + {transactionDetails?.kind !== 'P' && ( + + )} + + {transactionDetails?.kind !== 'P' && ( + + )} + {/* Tab Content */} @@ -285,6 +340,7 @@ const DetailTransaction = () => { let status; let badgeClass; + if (transactionDetails?.status === 'C') { status = 'COMPLETE'; badgeClass = 'bg-green-100 text-green-800'; @@ -294,6 +350,7 @@ const DetailTransaction = () => { } else if (transactionDetails?.status === 'O') { status = 'ON PROCESS'; badgeClass = 'bg-blue-100 text-blue-800'; + } else if (transactionDetails?.status === 'P') { } else if (transactionDetails?.status === 'P') { status = 'PENDING'; badgeClass = 'bg-gray-100 text-gray-800'; @@ -303,6 +360,12 @@ const DetailTransaction = () => { } else if (transactionDetails?.status === 'S') { status = 'REVERSAL'; badgeClass = 'bg-purple-100 text-purple-800'; + } else if (transactionDetails?.status === 'R') { + status = 'ROLLBACK'; + badgeClass = 'bg-yellow-100 text-yellow-800'; + } else if (transactionDetails?.status === 'S') { + status = 'REVERSAL'; + badgeClass = 'bg-purple-100 text-purple-800'; } return ( @@ -329,7 +392,7 @@ const DetailTransaction = () => { kind = 'TOP UP'; } else if (transactionDetails?.kind === 'R') { kind = 'RETURN'; - } else if (transactionDetails?.kind === 'E') { + }else if (transactionDetails?.kind === 'E') { kind = 'REWARD'; } else if (transactionDetails?.kind === 'L') { kind = 'PURCHASE LOJA'; @@ -395,59 +458,60 @@ const DetailTransaction = () => { )} - {activeTab === 'detail' && transactionDetails?.kind == 'P' && ( -
-

- Product Information - - Product Info - -

-
-
-

Product Name

-

- {transactionDetails?.purchase?.product?.name ?? "-"} -

-
-
-

Price Cash

-

- {transactionDetails?.purchase?.product?.price_cash != null - ? new Intl.NumberFormat("en-US", { style: "currency", currency: "USD" }).format(transactionDetails.purchase.product.price_cash) - : "-"} -

-
-
-

Price Point

-

- {transactionDetails?.purchase?.product?.price_point ?? "-"} -

-
-
-

Product Type

-

- {transactionDetails?.purchase?.product?.type ?? "-"} -

-
-
-

Provider Name

-

- {transactionDetails?.purchase?.product?.provider?.description ?? "-"} -

-
-
-

Provider Type

-

- {transactionDetails?.purchase?.product?.provider?.type === "h2h" - ? "HOST TO HOST" - : transactionDetails?.purchase?.product?.provider?.type === "agent" - ? "AGENT" + + {activeTab === 'detail' && transactionDetails?.kind == 'P' && transactionDetails?.kind == 'P' && ( +

+

+ Product Information + + Product Info + +

+
+
+

Product Name

+

+ {transactionDetails?.purchase?.product?.name ?? "-"} +

+
+
+

Price Cash

+

+ {transactionDetails?.purchase?.product?.price_cash != null + ? new Intl.NumberFormat("en-US", { style: "currency", currency: "USD" }).format(transactionDetails.purchase.product.price_cash) : "-"} -

+

+
+
+

Price Point

+

+ {transactionDetails?.purchase?.product?.price_point ?? "-"} +

+
+
+

Product Type

+

+ {transactionDetails?.purchase?.product?.type ?? "-"} +

+
+
+

Provider Name

+

+ {transactionDetails?.purchase?.product?.provider?.description ?? "-"} +

+
+
+

Provider Type

+

+ {transactionDetails?.purchase?.product?.provider?.type === "h2h" + ? "HOST TO HOST" + : transactionDetails?.purchase?.product?.provider?.type === "agent" + ? "AGENT" + : "-"} +

+
-
)} {activeTab === 'detail' && transactionDetails?.kind != 'P' && transactionDetails?.transfer != null && ( @@ -494,15 +558,21 @@ const DetailTransaction = () => { let status; let badgeClass; + let badgeClass; + if (transactionDetails?.status === 'C') { status = 'COMPLETE'; badgeClass = 'bg-green-100 text-green-800'; + badgeClass = 'bg-green-100 text-green-800'; } else if (transactionDetails?.status === 'F') { status = 'FAILED'; badgeClass = 'bg-red-100 text-red-800'; + badgeClass = 'bg-red-100 text-red-800'; } else if (transactionDetails?.status === 'O') { status = 'ON PROCESS'; badgeClass = 'bg-blue-100 text-blue-800'; + } else if (transactionDetails?.status === 'P') { + badgeClass = 'bg-blue-100 text-blue-800'; } else if (transactionDetails?.status === 'P') { status = 'PENDING'; badgeClass = 'bg-gray-100 text-gray-800'; @@ -514,6 +584,20 @@ const DetailTransaction = () => { badgeClass = 'bg-purple-100 text-purple-800'; } + return ( + + {status} + + ); + badgeClass = 'bg-gray-100 text-gray-800'; + } else if (transactionDetails?.status === 'R') { + status = 'ROLLBACK'; + badgeClass = 'bg-yellow-100 text-yellow-800'; + } else if (transactionDetails?.status === 'S') { + status = 'REVERSAL'; + badgeClass = 'bg-purple-100 text-purple-800'; + } + return ( {status} @@ -537,6 +621,7 @@ const DetailTransaction = () => { kind = 'TOP UP'; } else if (transactionDetails?.kind === 'R') { kind = 'RETURN'; + } else if (transactionDetails?.kind === 'E') { } else if (transactionDetails?.kind === 'E') { kind = 'REWARD'; } @@ -666,6 +751,7 @@ const DetailTransaction = () => {
)} + {activeTab === 'destinationwallet' && transactionDetails?.kind?.trim()?.toUpperCase() !== 'P' && ( {activeTab === 'destinationwallet' && transactionDetails?.kind?.trim()?.toUpperCase() !== 'P' && (

Destination Wallet

@@ -725,7 +811,7 @@ const DetailTransaction = () => { Type Request Date Response Date - Response Body + {/* Response Body */} Response Code Request Endpoint @@ -796,6 +882,7 @@ const DetailTransaction = () => {
)} + {activeTab === 'approve' && transactionDetails?.kind == "P" && ( {activeTab === 'approve' && transactionDetails?.kind == "P" && (

Approval Logs

@@ -872,7 +959,7 @@ const DetailTransaction = () => { Type Request Date Response Date - Response Body + {/* Response Body */} Response Code Request Endpoint