Spaces:
Runtime error

File size: 3,015 Bytes
936e5c6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
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>
  )
}