Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement the frontend page for recipient's data input using ppa #26 #131

Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
8522577
feat: Implemented the sqr code
Blindspot22 Apr 11, 2024
7d9373b
feat(power-pay-frontend): mordified the main.tsx, index.tsx and mplem…
Tekum-Emmanuella Apr 11, 2024
b4afc6e
feat: Implemented the fake api and called it in the userinfo.tsx
Ngha-Boris Apr 12, 2024
12ffd5b
Fix: fixed the test which was failing due to the changes made in the …
Ngha-Boris Apr 13, 2024
3ebaba1
Delete power-pay-frontend/dev-dist/sw.js
Ngha-Boris Apr 15, 2024
0cedb0c
Delete power-pay-frontend/dev-dist/workbox-b5f7729d.js
Ngha-Boris Apr 15, 2024
b4f29ce
Delete power-pay-frontend/dev-dist/registerSW.js
Ngha-Boris Apr 15, 2024
ba1499d
feat(power-pay-frontend): mordified the userinfo.tsx to move all cont…
Tekum-Emmanuella Apr 17, 2024
3733593
feat(power-pay-frontend): mordified the userinfo.tsx to move all cont…
Tekum-Emmanuella Apr 17, 2024
e54af47
Update(frontend): Mordified the userinfo fo manual input. Made it res…
Tekum-Emmanuella Apr 17, 2024
ce8fb76
Merge branch 'Implement-the-frontend-page-for-recipient's-data-input-…
Tekum-Emmanuella Apr 17, 2024
ef30c09
Renamed src/components/index.tsx to paymentoption.tsx
Tekum-Emmanuella Apr 17, 2024
db0e2cf
Merge branch 'ADORSYS-GIS:main' into Implement-the-frontend-page-for-…
Tekum-Emmanuella Apr 17, 2024
ac2526f
Fix(frontend): Renamed the index file in the components folder to pay…
Tekum-Emmanuella Apr 17, 2024
e06d304
Merge branch 'Implement-the-frontend-page-for-recipient's-data-input-…
Tekum-Emmanuella Apr 17, 2024
2741c0d
Fix(frontend): Removed the uneccessary imports fron the files.
Tekum-Emmanuella Apr 17, 2024
3a51951
Fix(frontend): Removed the fake Api link from the userinfo file.
Tekum-Emmanuella Apr 18, 2024
f2dcc0e
Merge branch 'main' into Implement-the-frontend-page-for-recipient's-…
Ngha-Boris Apr 18, 2024
927fd24
Fix: fix the fake api
Ngha-Boris Apr 18, 2024
26649a2
updated the QR-Scan option
Blindspot22 Apr 22, 2024
3cc78af
Merge branch 'main' into Implement-the-frontend-page-for-recipient's-…
Ngha-Boris Apr 23, 2024
6584798
Rename userinfo.tsx to RecipientInfo.tsx
Tekum-Emmanuella May 7, 2024
e29b487
Update route.tsx
Tekum-Emmanuella May 7, 2024
28a1b64
Update RecipientInfo.tsx
Tekum-Emmanuella May 7, 2024
8ef0f30
Update paymentoption.tsx
Tekum-Emmanuella May 7, 2024
e8faaa2
Update paymentoption.tsx
Tekum-Emmanuella May 7, 2024
2531f0c
deleted: deleted paymentoption.tsx since they where two
Ngha-Boris Jun 11, 2024
43ec1f5
update: Updated the RecipientInfo
Ngha-Boris Jun 11, 2024
d36a452
update: Added type button to the QR Scan button
Ngha-Boris Jun 12, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions paymentoption.tsx
Ngha-Boris marked this conversation as resolved.
Show resolved Hide resolved
Motouom marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import React, { useState } from 'react';
import QRScannerComponent from './scan_rq';
import UserInfo from './userinfo'; // Import the UserInfo component
import { Link } from "react-router-dom";

const PaymentOptions: React.FC = () => {
Tekum-Emmanuella marked this conversation as resolved.
Show resolved Hide resolved
const [showQRScanner, setShowQRScanner] = useState<boolean>(false);
const [showInputManually, setShowInputManually] = useState<boolean>(false);

const handleScanQRClick = () => {
setShowQRScanner(true);
setShowInputManually(false); // Close InputManuallyComponent if open
};

const handleInputManuallyClick = () => {
setShowInputManually(true);
setShowQRScanner(false); // Close QRScannerComponent if open
};

return (
<div className="container">
<div className="bg-gray-100 absolute inset-x-6 top-12 h-40 rounded-lg">
<h5 className="h-auto text-center pt-9 mb-2 text-2xl font-bold tracking-tight text-black">Payment Option.</h5>
<h5 className="text-center pt-9 mb-2 text-black">Choose the option you wish to pay</h5>
</div>
<div className="pt-12">
<Link to={`UserInfo`}>
<button onClick={handleInputManuallyClick} className='bg-blue-950 rounded-full w-80 m-auto px-4 text-white text-lg absolute inset-x-0 mb-20 bottom-12'>Input Manually</button>
<br></br>
</Link>
<div className="pt-12">
<button onClick={handleScanQRClick} className="bg-blue-950 rounded-full w-80 m-auto px-4 text-white text-lg absolute inset-x-0 bottom-12">
QR Scan
</button>
</div>
</div>
{showQRScanner && <QRScannerComponent />}
{showInputManually && <UserInfo />} {/* Render UserInfo component when showInputManually is true */}
</div>
);
};

export default PaymentOptions
913 changes: 510 additions & 403 deletions power-pay-frontend/package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions power-pay-frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"preview": "vite preview"
},
"dependencies": {
"@yudiel/react-qr-scanner": "^2.0.0-beta.3",
"axios": "^1.6.8",
"react": "^18.2.0",
"react-dom": "^18.2.0"
Expand Down
61 changes: 61 additions & 0 deletions power-pay-frontend/src/components/fake_api.tsx
Ngha-Boris marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import axios, { AxiosError, AxiosResponse } from 'axios';

export interface ApiResponse {
phone: string;
amount: string;
}

export interface ErrorResponse {
message: string;
}

const FakeApi = () => {
Motouom marked this conversation as resolved.
Show resolved Hide resolved
const baseURL = 'http://localhost:5000';
const api = axios.create({
baseURL,
timeout: 5000,
});

const mockSend_MoneyAPI = async (
recipientPhoneNumber: string,
amount: number
): Promise<ApiResponse | undefined> => {
try {
if (!recipientPhoneNumber || !amount) {
throw new Error("Please fill in all fields");
}

const response: AxiosResponse<ApiResponse> = await api.post('/UserInfo', {
recipientPhoneNumber,
amount,
});

console.log("Transaction Successful");
console.log("Recipient Phone Number:", recipientPhoneNumber);
console.log("Amount:", amount);

return response.data;
} catch (error) {
if (axios.isAxiosError(error)) {
const axiosError = error as AxiosError<ErrorResponse>;
if (axiosError.response) {
// Server returned an error response
console.log(axiosError.response.data.message || "An error occurred while processing the transaction.");
} else if (axiosError.request) {
// No response received, possibly due to network issues
console.log("Network error. Please check your internet connection.");
} else {
// Something else went wrong
console.log("An error occurred while processing the transaction.");
}
} else {
// Non-Axios errors
console.log("An error occurred while processing the transaction.");
}
}
};

return mockSend_MoneyAPI; // Return the function directly
};

export default FakeApi;
43 changes: 43 additions & 0 deletions power-pay-frontend/src/components/paymentoption.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import React, { useState } from 'react';
import QRScannerComponent from './scan_rq';
import UserInfo from './userinfo'; // Import the UserInfo component
import { Link } from "react-router-dom";

const PaymentOptions: React.FC = () => {
const [showQRScanner, setShowQRScanner] = useState<boolean>(false);
const [showInputManually, setShowInputManually] = useState<boolean>(false);

const handleScanQRClick = () => {
setShowQRScanner(true);
setShowInputManually(false); // Close InputManuallyComponent if open
};

const handleInputManuallyClick = () => {
setShowInputManually(true);
setShowQRScanner(false); // Close QRScannerComponent if open
};

return (
<div className="container">
<div className="bg-gray-100 absolute inset-x-6 top-12 h-40 rounded-lg">
<h5 className="h-auto text-center pt-9 mb-2 text-2xl font-bold tracking-tight text-black">Payment Option.</h5>
<h5 className="text-center pt-9 mb-2 text-black">Choose the option you wish to pay</h5>
</div>
<div className="pt-12">
<Link to={`UserInfo`}>
<button onClick={handleInputManuallyClick} className='bg-blue-950 rounded-full w-80 m-auto px-4 text-white text-lg absolute inset-x-0 mb-20 bottom-12'>Input Manually</button>
<br></br>
</Link>
<div className="pt-12">
<button onClick={handleScanQRClick} className="bg-blue-950 rounded-full w-80 m-auto px-4 text-white text-lg absolute inset-x-0 bottom-12">
Motouom marked this conversation as resolved.
Show resolved Hide resolved
QR Scan
</button>
</div>
</div>
{showQRScanner && <QRScannerComponent />}
{showInputManually && <UserInfo />} {/* Render UserInfo component when showInputManually is true */}
</div>
);
};

export default PaymentOptions
45 changes: 45 additions & 0 deletions power-pay-frontend/src/components/scan_rq.tsx
Ngha-Boris marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { useEffect, useRef as ref } from 'react';
import { Scanner as S } from '@yudiel/react-qr-scanner'; // Importing Scanner from @yudiel/react-qr-scanner
const Scanner: any = S;


const QRScannerComponent = () => {
Tekum-Emmanuella marked this conversation as resolved.
Show resolved Hide resolved

const qrScannerRef = ref<any>(null);
useEffect(() => {
if (qrScannerRef.current) {
qrScannerRef.current.start();
}

return () => {
if (qrScannerRef.current) {
qrScannerRef.current.stop();
}
};
}, []);

const handleScan = (data: string | null) => {
if (data) {
console.log('Scanned data:', data);
}
};

const handleError = (err: any) => {
console.error('QR scanner error:', err);
};
Ngha-Boris marked this conversation as resolved.
Show resolved Hide resolved

return (
<div>
<Scanner
ref={qrScannerRef}
on={handleScan}
onError={handleError}
facingMode="environment"
style={{ width: '100%', height: 'auto' }}
/>
<button onClick={() => qrScannerRef.current?.start()}>Start Scan</button>
</div>
);
};

export default QRScannerComponent;
74 changes: 74 additions & 0 deletions power-pay-frontend/src/components/userinfo.tsx
Ngha-Boris marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import React from 'react';
import { useFormik } from 'formik';
import { Link } from 'react-router-dom';
import FakeApi from './fake_api';

const UserInfo: React.FC = () => {
Tekum-Emmanuella marked this conversation as resolved.
Show resolved Hide resolved
const mockSend_MoneyAPI = FakeApi(); // Call the FakeApi function to get the function mockSend_MoneyAPI

const formik = useFormik({
initialValues: {
phone: '',
amount: ''
},
onSubmit: async (values) => {
try {
// Call the mockSend_MoneyAPI function
const response = await mockSend_MoneyAPI(values.phone, parseInt(values.amount));
console.log("API Response:", response);
// Handle success, navigate to next step, etc.
} catch (error: any) {
// Handle errors thrown by the mockSend_MoneyAPI function
console.error("An error occurred:", error.message);

}
}
});

const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
const { name, value } = event.target;
// Allow only numbers in the input fields
const newValue = value.replace(/[^\d]/g, '');
formik.setFieldValue(name, newValue);
};

return (
<div className="max-w-md1 flex justify-center">
<form onSubmit={formik.handleSubmit}>
<div className="absolute top-0 left-0 mt- ml-4">
<Link to={`PaymentOptions`}>
<button className="hover:bg-blue-700 text-black font-bold py-61 px-4 rounded">
&larr;
</button>
</Link>
</div>
<div className="mb-4">
<input
type="text"
id="phone"
name="phone"
placeholder='Phone Number'
onChange={handleChange}
value={formik.values.phone}
style={{ color: 'black' }}
className="mt-1 p-2 border border-gray-300 rounded-full w-full bg-white"
/>
</div>
<div className="mb-4">
<input
type="text"
id="amount"
name="amount"
placeholder="Amount"
onChange={handleChange}
value={formik.values.amount}
className="mt-1 p-2 border border-gray-300 rounded-full w-full bg-white"
/>
</div>
<button type="submit" className="rounded-full bg-blue-950 hover:bg-blue-950 w-80 m-auto px-4 py-2 text-white text-lg absolute inset-x-0 bottom-12">Submit</button>
</form>
</div>
);
}

export default UserInfo;
3 changes: 1 addition & 2 deletions power-pay-frontend/src/main.tsx
Tekum-Emmanuella marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ import React from 'react'
import ReactDOM from 'react-dom/client'
import App from './App.tsx'
import './index.css'

ReactDOM.createRoot(document.getElementById('root')!).render(
<React.StrictMode>
<App />
</React.StrictMode>,
)
)
1 change: 1 addition & 0 deletions power-pay-frontend/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"lib": ["ES2020", "DOM", "DOM.Iterable", "webworker"],
"module": "ESNext",
"skipLibCheck": true,
"noImplicitUseStrict": false,

/* Bundler mode */
"moduleResolution": "bundler",
Expand Down
Loading