Spaces:
Runtime error
Runtime error
Download components/TransferForm.jsx from mehdabdelkader/anycoder-a17edbde: direct link, hf CLI and curl.
- Browser
- Download file 3.02 kB
-
https://huggingface.co/spaces/mehdabdelkader/anycoder-a17edbde/resolve/main/components/TransferForm.jsx
- Command line
-
hf download hf://spaces/mehdabdelkader/anycoder-a17edbde/components/TransferForm.jsx
-
curl -L -o TransferForm.jsx https://huggingface.co/spaces/mehdabdelkader/anycoder-a17edbde/resolve/main/components/TransferForm.jsx
3.02 kB
| import { useState } from 'react' | |
| import { FaExchangeAlt, FaMoneyBillWave } from 'react-icons/fa' | |
| export default function TransferForm() { | |
| const [amount, setAmount] = useState('') | |
| const [source, setSource] = useState('Waafi') | |
| const [destination, setDestination] = useState('DMoney') | |
| const [loading, setLoading] = useState(false) | |
| const [error, setError] = useState('') | |
| const [success, setSuccess] = useState(false) | |
| const handleSubmit = async (e) => { | |
| e.preventDefault() | |
| setLoading(true) | |
| setError('') | |
| try { | |
| // Simulate API call | |
| await new Promise(resolve => setTimeout(resolve, 1500)) | |
| setSuccess(true) | |
| } catch (err) { | |
| setError('Erreur lors du transfert') | |
| } finally { | |
| setLoading(false) | |
| } | |
| } | |
| const swapServices = () => { | |
| const temp = source | |
| setSource(destination) | |
| setDestination(temp) | |
| } | |
| return ( | |
| <form onSubmit={handleSubmit} className="bg-white p-6 rounded-lg shadow-md"> | |
| <div className="mb-4"> | |
| <label className="block text-gray-700 mb-2">Montant (DJF)</label> | |
| <input | |
| type="number" | |
| value={amount} | |
| onChange={(e) => setAmount(e.target.value)} | |
| className="w-full p-3 border rounded-lg" | |
| placeholder="Entrez le montant" | |
| required | |
| /> | |
| </div> | |
| <div className="flex items-center justify-between mb-6"> | |
| <div className="text-center"> | |
| <p className="font-medium">De</p> | |
| <select | |
| value={source} | |
| onChange={(e) => setSource(e.target.value)} | |
| className="p-2 border rounded-lg" | |
| > | |
| <option value="Waafi">Waafi</option> | |
| <option value="DMoney">DMoney</option> | |
| </select> | |
| </div> | |
| <button | |
| type="button" | |
| onClick={swapServices} | |
| className="p-2 bg-gray-200 rounded-full hover:bg-gray-300" | |
| > | |
| <FaExchangeAlt className="text-blue-600" /> | |
| </button> | |
| <div className="text-center"> | |
| <p className="font-medium">Vers</p> | |
| <select | |
| value={destination} | |
| onChange={(e) => setDestination(e.target.value)} | |
| className="p-2 border rounded-lg" | |
| > | |
| <option value="DMoney">DMoney</option> | |
| <option value="Waafi">Waafi</option> | |
| </select> | |
| </div> | |
| </div> | |
| {error && <p className="text-red-500 mb-4">{error}</p>} | |
| {success && ( | |
| <div className="bg-green-100 text-green-700 p-3 rounded-lg mb-4"> | |
| Transfert réussi! | |
| </div> | |
| )} | |
| <button | |
| type="submit" | |
| disabled={loading} | |
| className={`w-full py-3 px-4 rounded-lg text-white font-medium ${loading ? 'bg-blue-400' : 'bg-blue-600 hover:bg-blue-700'}`} | |
| > | |
| {loading ? 'Transfert en cours...' : ( | |
| <> | |
| <FaMoneyBillWave className="inline mr-2" /> | |
| Transférer | |
| </> | |
| )} | |
| </button> | |
| </form> | |
| ) | |
| } |