File size: 7,463 Bytes
5618501
 
 
 
 
f5c1be6
5618501
4e9aca1
f5c1be6
 
 
4e9aca1
 
 
 
f5c1be6
4e9aca1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f5c1be6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4e9aca1
f5c1be6
 
 
 
4e9aca1
 
 
f5c1be6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4e9aca1
f5c1be6
 
 
 
 
 
 
 
4e9aca1
 
f5c1be6
4e9aca1
f5c1be6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4e9aca1
f5c1be6
 
 
 
4e9aca1
 
5618501
 
 
f5c1be6
 
 
 
 
 
 
 
 
5618501
 
 
f5c1be6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5618501
f5c1be6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5618501
 
f5c1be6
4e9aca1
5618501
 
 
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>User Profile</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet">
    <style>
       body {
        background-color: #FDF4E3;
    }
        .back-to-menu {
            display: block;
            margin: 30px auto 10px auto;
            padding: 10px 20px;
            background-color: #ff5722;
            color: #ffffff;
            border: none;
            border-radius: 25px;
            font-size: 1rem;
            font-weight: bold;
            text-align: center;
            text-decoration: none;
            width: 100%;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
            transition: background-color 0.3s ease;
        }
        .back-to-menu:hover {
            background-color: #e64a19;
            text-decoration: none;
        }
        .editable {
            background-color: #f0f8ff; /* Light blue when edited */
        }
        .input-group {
            position: relative;
        }
        .btn-change {
            position: absolute;
            right: 10px;
            top: 50%;
            transform: translateY(-50%);
            background-color: #ffffff;
            color: #0FAA39; /* Green text color */
            border: none; /* No border */
            border-radius: 5px;
            padding: 5px 10px;
            cursor: pointer;
            font-size: 0.9rem;
        }
        .btn-change:hover {
            background-color: #ffffff;
            color: #0FAA39;
        }
        .copy-btn {
            position: absolute;
            right: 10px;
            top: 50%;
            transform: translateY(-50%);
            background: none;
            border: none;
            color: #007bff;
            font-size: 1.2rem;
            cursor: pointer;
        }
        .update-btn {
            background-color: #0FAA39;
            color: white;
            border: none;
            border-radius: 5px;
            padding: 10px 20px;
            font-size: 1rem;
            cursor: pointer;
        }
        .update-btn:hover {
            background-color: #0f8e29;
        }
        .edit-btn {
            background-color: #0FAA39;
            color: white;
            border: none;
            border-radius: 5px;
            padding: 10px 20px;
            font-size: 1rem;
            cursor: pointer;
        }
        .edit-btn:hover {
            background-color: #0f8e29;
        }
           /* Change text color to #ff5722 */
        h1, .form-label {
        color: #ff5722;
        }
    </style>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script>
        function enableEditField(fieldId) {
            var field = document.getElementById(fieldId);
            field.removeAttribute("readonly");
            field.classList.add("editable");
            field.focus();
        }

        function updateProfile(event) {
            event.preventDefault();
            var formData = $('#profileForm').serialize();

            $.ajax({
                type: "POST",
                url: "/update_profile",  
                data: formData,
                success: function(response) {
                    if (response.status === "success") {
                        alert(response.message);
                        location.reload();
                    } else {
                        alert(response.message);
                    }
                },
                error: function() {
                    alert("An error occurred while updating the profile.");
                }
            });
        }

        function editProfileFields() {
            // Making only editable fields editable (Excluding referralCode and rewardPoints)
            document.getElementById('customerName').removeAttribute('readonly');
            document.getElementById('email').removeAttribute('readonly');
            document.getElementById('phone').removeAttribute('readonly');
            document.getElementById('customerName').classList.add('editable');
            document.getElementById('email').classList.add('editable');
            document.getElementById('phone').classList.add('editable');
        }

        function copyReferralCode() {
            var referralCode = document.getElementById('referralCode');
            referralCode.select();
            document.execCommand('copy');
            alert('Referral Code Copied!');
        }
    </script>
</head>
<body>
    <div class="container mt-4">
        <h1>User Profile</h1>

        {% with messages = get_flashed_messages(with_categories=true) %}
            {% if messages %}
                <div class="alert alert-{{ messages[0][0] }}">
                    {{ messages[0][1] }}
                </div>
            {% endif %}
        {% endwith %}

        <div class="card">
            <div class="card-body">
                <form id="profileForm" method="POST" onsubmit="updateProfile(event)">
                    <div class="mb-3">
                        <label for="customerName" class="form-label"><strong>Name:</strong></label>
                        <div class="input-group">
                            <input type="text" id="customerName" name="customerName" class="form-control" value="{{ customer['name'] }}" readonly>
                        </div>
                    </div>

                    <div class="mb-3">
                        <label for="email" class="form-label"><strong>Email:</strong></label>
                        <div class="input-group">
                            <input type="email" id="email" name="email" class="form-control" value="{{ customer['email'] }}" readonly>
                        </div>
                    </div>

                    <div class="mb-3">
                        <label for="phone" class="form-label"><strong>Phone:</strong></label>
                        <div class="input-group">
                            <input type="text" id="phone" name="phone" class="form-control" value="{{ customer['phone'] }}" readonly>
                        </div>
                    </div>

                    <div class="mb-3">
                        <label for="referralCode" class="form-label"><strong>Referral Code:</strong></label>
                        <div class="input-group">
                            <input type="text" id="referralCode" name="referralCode" class="form-control" value="{{ customer['referral_code'] }}" readonly>
                            <button type="button" class="copy-btn" onclick="copyReferralCode()">📋</button>
                        </div>
                    </div>

                    <div class="mb-3">
                        <label for="rewardPoints" class="form-label"><strong>Reward Points:</strong></label>
                        <input type="text" id="rewardPoints" name="rewardPoints" class="form-control" value="{{ customer['reward_points'] }}" readonly>
                    </div>

                    <button type="button" class="edit-btn" onclick="editProfileFields()">Edit Profile</button>
                    <button type="submit" class="update-btn">Update Profile</button>
                </form>
            </div>
        </div>

        <a href="/menu" class="back-to-menu">Back to Menu</a>
    </div>
</body>
</html>