From d7071b300778b233f150b58c6005d402ede8bad1 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Fri, 21 Oct 2022 15:14:13 -0300 Subject: autofocus --- packages/bank/src/pages/home/index.tsx | 201 ++++++++++++++++----------------- 1 file changed, 98 insertions(+), 103 deletions(-) (limited to 'packages') diff --git a/packages/bank/src/pages/home/index.tsx b/packages/bank/src/pages/home/index.tsx index 6bda5c2..0a2a5a5 100644 --- a/packages/bank/src/pages/home/index.tsx +++ b/packages/bank/src/pages/home/index.tsx @@ -932,17 +932,17 @@ function PaytoWireTransfer(Props: any): VNode { const [submitData, submitDataSetter] = useWireTransferRequestType(); const [rawPaytoInput, rawPaytoInputSetter] = useRawPaytoInputType(); const i18n = useTranslator(); + const { focus, backendState } = Props const amountRegex = '^[0-9]+(\.[0-9]+)?$'; const ibanRegex = '^[A-Z][A-Z][0-9]+$'; const receiverInput = ''; const subjectInput = ''; let transactionData: TransactionRequestType; - const focusInput = useRef(null); + const ref = useRef(null) useEffect(() => { - console.log('Now focus', focusInput); - if (focusInput.current) - (focusInput.current as any).focus(); - }, []); + if (focus) ref.current?.focus(); + },[]); + if (!pageState.isRawPayto) { console.log('wire transfer form'); return ( @@ -952,12 +952,11 @@ function PaytoWireTransfer(Props: any): VNode {

  { @@ -981,7 +980,7 @@ function PaytoWireTransfer(Props: any): VNode { }} />

  @@ -1134,7 +1133,6 @@ function TalerWithdrawalConfirmationQuestion(Props: any): VNode { name="answer" id="answer" type="text" - autofocus required onInput={(e): void => { captchaAnswer = e.currentTarget.value; @@ -1274,84 +1272,70 @@ function TalerWithdrawalQRCode(Props: any): VNode { -/* FIXME: find a way to get rid of the @ts-ignore here! Sebastian: fix my evil DOM modification */ -function OpenPayTab(evt: MouseEvent, tabName: string) { - let tabcontent = document.getElementsByClassName("tabcontent"); - for (let i = 0; i < tabcontent.length; i++) { - // @ts-ignore - tabcontent[i].style.display = "none"; - } - let tablinks = document.getElementsByClassName("tablinks"); - for (let i = 0; i < tablinks.length; i++) { - tablinks[i].className - = tablinks[i].className.replace(" active", ""); - } - // @ts-ignore - document.getElementById(tabName).style.display = "block"; - // @ts-ignore - evt.currentTarget.className += " active"; -} - - function WalletWithdraw(Props: any): VNode { - const { backendState, pageStateSetter } = Props; + const { backendState, pageStateSetter, focus } = Props; const currency = useContext(CurrencyContext); const i18n = useTranslator(); let submitAmount = '5.00'; const amountRegex = '^[0-9]+(\.[0-9]+)?$'; + const ref = useRef(null) + useEffect(() => { + if (focus) ref.current?.focus(); + },[]); return ( -

-

-   - { - // FIXME: validate using 'parseAmount()', - // deactivate submit button as long as - // amount is not valid - submitAmount = e.currentTarget.value; - }} /> -   - -

-

-

- { - submitAmount = validateAmount(submitAmount); - /** - * By invalid amounts, the validator prints error messages - * on the console, and the browser colourizes the amount input - * box to indicate a error. - */ - if (!submitAmount) return; - createWithdrawalCall( - `${currency}:${submitAmount}`, - backendState, - pageStateSetter - ) - }} /> -
-

-
+
+

+   + { + // FIXME: validate using 'parseAmount()', + // deactivate submit button as long as + // amount is not valid + submitAmount = e.currentTarget.value; + }} /> +   + +

+

+

+ { + submitAmount = validateAmount(submitAmount); + /** + * By invalid amounts, the validator prints error messages + * on the console, and the browser colourizes the amount input + * box to indicate a error. + */ + if (!submitAmount) return; + createWithdrawalCall( + `${currency}:${submitAmount}`, + backendState, + pageStateSetter + ) + }} /> +
+

+
) } @@ -1361,34 +1345,43 @@ function WalletWithdraw(Props: any): VNode { * then specify the details trigger the action. */ function PaymentOptions(Props: any): VNode { - const { backendState, pageStateSetter } = Props; + const { backendState, pageStateSetter, focus } = Props; const currency = useContext(CurrencyContext); const i18n = useTranslator(); + const [tab, setTab] = useState<"charge-wallet"|"wire-transfer">("charge-wallet") + + return (
- -
-
-

{i18n`Charge Taler wallet`}

- -
-
-

{i18n`Wire to bank account`}

- -
+ { tab === "charge-wallet" && +
+

{i18n`Charge Taler wallet`}

+ +
+ } + { tab === "wire-transfer" && +
+

{i18n`Wire to bank account`}

+ +
+ }
); } @@ -1399,7 +1392,6 @@ function RegistrationButton(Props: any): VNode { if (UI_ALLOW_REGISTRATIONS) { return (