diff --git a/components/Constraint/index.js b/components/Constraint/index.js index b60c294..dfb2755 100644 --- a/components/Constraint/index.js +++ b/components/Constraint/index.js @@ -1,15 +1,17 @@ -import React, { useState } from 'react'; +import React, { useRef, useState } from 'react'; import Image from "next/image"; -import {Button, Form, Input} from "antd"; +import {Button, Form, Input, Spin} from "antd"; import Transaction from "../Transaction"; import { botsRepository } from '../../repository/bots'; -const Constraint = ({location}) => { +const Constraint = ({ location }) => { const [form] = Form.useForm(); const [orderId, setOrderId] = useState(''); const [order, setOrder] = useState(''); const [orderNotFound, setOrderNotFound] = useState(false); const [show, setShow] = useState(false) + const [loading, setLoading] = useState(false) + const inputRef = useRef(null) const handleChangeCheckTransaction = (e) => { const value = e.target.value @@ -17,32 +19,38 @@ const Constraint = ({location}) => { } const onSubmit = async () => { - setShow(true) - if (show) { - try { - const res = await botsRepository.api.useCheckTransactionByOrderId(orderId); - const resultTransaction = res?.data; - setOrderNotFound(false); - setOrder(resultTransaction); - - } catch (err) { - setOrderNotFound(true); + try { + setLoading(true) + const value = await form.getFieldValue() + if (inputRef.current) { + setShow(true) } + const res = await botsRepository.api.useCheckTransactionByOrderId(value?.order_id); + const resultTransaction = res?.data; + setOrderNotFound(false); + setOrder(resultTransaction); + setTimeout(() => { + setLoading(false) + }, 1000); + + } catch (err) { + if (err) { + setLoading(false) + } + setOrderNotFound(true); } } - console?.log(order, "ini ordernya") - return (
- +

Ada kendala dengan transaksimu?

Cek transaksi dengan Order ID pembayaran:

-
+ { @@ -72,33 +81,37 @@ const Constraint = ({location}) => { {orderNotFound || order === undefined ? ( - <> -

Status Transaksi

+ loading ? () : ( +
+

Status Transaksi

-
- -
- {orderId} - BELUM ADA TRANSAKSI +
+ +
+ {orderId} + BELUM ADA TRANSAKSI +
+
-
- + ) ) : order ? ( - <> -

Status Transaksi

+ loading ? () : ( +
+

Status Transaksi

-
- -
- {orderId} +
+ +
+ {orderId} +
+
+
-
- - + ) ) : ''}
)