lokeshloki143 commited on
Commit
07e25a4
·
verified ·
1 Parent(s): 9eefad3

Update templates/customer_details.html

Browse files
Files changed (1) hide show
  1. templates/customer_details.html +175 -199
templates/customer_details.html CHANGED
@@ -7,255 +7,231 @@
7
  <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
8
  <style>
9
  body {
10
- background-color: #FDF4E3;
 
 
 
11
  }
12
-
13
- .back-to-menu {
14
- display: block;
15
- margin: 30px auto 10px auto;
16
- padding: 10px 20px;
17
- background-color: #ff5722;
18
- color: #ffffff;
19
- border: none;
20
- border-radius: 25px;
21
- font-size: 1rem;
22
- font-weight: bold;
23
- text-align: center;
24
- text-decoration: none;
25
- width: 100%;
26
- box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
27
- transition: background-color 0.3s ease;
28
  }
29
-
30
- .back-to-menu:hover {
31
- background-color: #e64a19;
 
 
 
 
 
32
  text-decoration: none;
 
 
 
33
  }
34
-
35
- .editable {
36
- background-color: #f0f8ff; /* Light blue when edited */
37
  }
38
-
39
- .input-group {
 
 
 
 
 
 
40
  position: relative;
41
  }
42
-
43
- .btn-change {
44
- position: absolute;
45
- right: 10px;
46
- top: 50%;
47
- transform: translateY(-50%);
48
- background-color: #ffffff;
49
- color: #0FAA39;
50
- border: none;
51
- border-radius: 5px;
52
- padding: 5px 10px;
53
- cursor: pointer;
54
- font-size: 0.9rem;
55
  }
56
-
57
- .btn-change:hover {
58
- background-color: #ffffff;
59
- color: #0FAA39;
 
 
 
 
 
 
60
  }
61
-
62
- .copy-btn {
 
 
63
  position: absolute;
64
  right: 10px;
65
  top: 50%;
66
  transform: translateY(-50%);
67
- background: none;
68
- border: none;
69
- color: #007bff;
70
- font-size: 1.2rem;
71
- cursor: pointer;
72
- }
73
-
74
- .update-btn {
75
- background-color: #0FAA39;
76
- color: white;
77
- border: none;
78
- border-radius: 5px;
79
- padding: 10px 20px;
80
- font-size: 1rem;
81
  cursor: pointer;
82
- width: 20%;
83
- font-weight: bold; /* Making the button text bold */
 
84
  }
85
-
86
- .update-btn:hover {
87
- background-color: #0f8e29;
88
  }
89
-
90
- .edit-btn {
91
- background-color: #0FAA39;
92
- color: white;
93
- border: none;
94
- border-radius: 5px;
95
- padding: 10px 20px;
 
96
  font-size: 1rem;
 
97
  cursor: pointer;
98
- width: 20%;
99
- font-weight: bold; /* Making the button text bold */
100
- }
101
-
102
- .edit-btn:hover {
103
- background-color: #0f8e29;
104
- }
105
-
106
-
107
-
108
- /* Button container adjustments */
109
- .button-container {
110
- display: flex;
111
- justify-content: space-between;
112
- gap: 10px; /* Add space between buttons */
113
- }
114
-
115
-
116
-
117
-
118
-
119
- /* Flexbox for equally spaced buttons */
120
- .button-container {
121
- display: flex;
122
- justify-content: space-between;
123
  margin-top: 20px;
124
  }
125
-
126
- /* Ensure both buttons have equal height and width */
127
- .edit-btn, .update-btn {
128
- flex: 1;
129
- margin: 0 5px;
130
- padding: 10px 20px;
131
- font-size: 1rem;
132
- cursor: pointer;
133
- border-radius: 5px;
134
- height: 50px; /* Equal height for both buttons */
135
- }
136
-
137
- /* Change text color inside input fields to gray */
138
- input[type="text"], input[type="email"], input[type="number"], .form-control {
139
- color: #808080; /* Change text color to gray */
140
- }
141
-
142
- /* Change color for the headings like Name, Email, Phone, Referral Code, Reward Points */
143
- .form-label {
144
- color: #1C1C1C; /* Change heading text color */
145
- }
146
-
147
- h1 {
148
- color: #1C1C1C; /* Change User Profile heading color */
149
- font-size: 24px; /* Change font size of 'User Profile' */
 
150
  }
151
  </style>
152
  <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
153
  <script>
154
- function enableEditField(fieldId) {
155
  var field = document.getElementById(fieldId);
156
- field.removeAttribute("readonly");
157
- field.classList.add("editable");
158
- field.focus();
 
 
 
 
 
 
 
 
 
 
 
159
  }
160
-
161
  function updateProfile(event) {
162
  event.preventDefault();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
163
  var formData = $('#profileForm').serialize();
164
-
165
  $.ajax({
166
  type: "POST",
167
- url: "/user/update_profile",
168
  data: formData,
 
169
  success: function(response) {
170
  if (response.status === "success") {
171
- alert(response.message);
172
  location.reload();
173
  } else {
174
- alert(response.message);
175
  }
176
  },
177
- error: function() {
178
- alert("An error occurred while updating the profile.");
 
179
  }
180
  });
181
  }
182
-
183
- function editProfileFields() {
184
- document.getElementById('customerName').removeAttribute('readonly');
185
- document.getElementById('email').removeAttribute('readonly');
186
- document.getElementById('phone').removeAttribute('readonly');
187
- document.getElementById('customerName').classList.add('editable');
188
- document.getElementById('email').classList.add('editable');
189
- document.getElementById('phone').classList.add('editable');
190
- }
191
-
192
- function copyReferralCode() {
193
- var referralCode = document.getElementById('referralCode');
194
- referralCode.select();
195
- document.execCommand('copy');
196
- alert('Referral Code Copied!');
197
- }
198
  </script>
199
  </head>
200
  <body>
201
- <div class="container mt-4">
202
- <h1>User Profile</h1>
203
-
204
- {% with messages = get_flashed_messages(with_categories=true) %}
205
- {% if messages %}
206
- <div class="alert alert-{{ messages[0][0] }}">
207
- {{ messages[0][1] }}
208
- </div>
209
- {% endif %}
210
- {% endwith %}
211
-
212
- <div class="card">
213
- <div class="card-body">
214
- <form id="profileForm" method="POST" onsubmit="updateProfile(event)">
215
- <div class="mb-3">
216
- <label for="customerName" class="form-label"><strong>Name:</strong></label>
217
- <div class="input-group">
218
- <input type="text" id="customerName" name="customerName" class="form-control" value="{{ customer['name'] }}" readonly>
219
- </div>
220
- </div>
221
 
222
- <div class="mb-3">
223
- <label for="email" class="form-label"><strong>Email:</strong></label>
224
- <div class="input-group">
225
- <input type="email" id="email" name="email" class="form-control" value="{{ customer['email'] }}" readonly>
226
- </div>
227
- </div>
228
 
229
- <div class="mb-3">
230
- <label for="phone" class="form-label"><strong>Phone:</strong></label>
231
- <div class="input-group">
232
- <input type="text" id="phone" name="phone" class="form-control" value="{{ customer['phone'] }}" readonly>
233
- </div>
234
- </div>
235
 
236
- <div class="mb-3">
237
- <label for="referralCode" class="form-label"><strong>Referral Code:</strong></label>
238
- <div class="input-group">
239
- <input type="text" id="referralCode" name="referralCode" class="form-control" value="{{ customer['referral_code'] }}" readonly>
240
- <button type="button" class="copy-btn" onclick="copyReferralCode()">📋</button>
241
- </div>
242
- </div>
243
 
244
- <div class="mb-3">
245
- <label for="rewardPoints" class="form-label"><strong>Reward Points:</strong></label>
246
- <input type="text" id="rewardPoints" name="rewardPoints" class="form-control" value="{{ customer['reward_points'] }}" readonly>
247
- </div>
 
248
 
249
- <!-- Flex container for Edit and Update buttons -->
250
- <div class="button-container">
251
- <button type="button" class="edit-btn" onclick="editProfileFields()">Edit Profile</button>
252
- <button type="submit" class="update-btn">Update Profile</button>
253
- </div>
254
- </form>
255
  </div>
256
- </div>
257
 
258
- <a href="/menu" class="back-to-menu">Back to Menu</a>
 
259
  </div>
260
  </body>
261
- </html>
 
7
  <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
8
  <style>
9
  body {
10
+ background-color: #F5F7FA;
11
+ font-family: Arial, sans-serif;
12
+ margin: 0;
13
+ padding: 0;
14
  }
15
+ .container {
16
+ max-width: 90%;
17
+ margin: 20px auto;
18
+ padding: 15px;
 
 
 
 
 
 
 
 
 
 
 
 
19
  }
20
+ .header {
21
+ display: flex;
22
+ align-items: center;
23
+ margin-bottom: 20px;
24
+ }
25
+ .back-btn {
26
+ font-size: 1.5rem;
27
+ color: #1C1C1C;
28
  text-decoration: none;
29
+ margin-right: 10px;
30
+ display: inline-flex;
31
+ align-items: center;
32
  }
33
+ .back-btn svg {
34
+ width: 24px;
35
+ height: 24px;
36
  }
37
+ .header h1 {
38
+ font-size: 1.25rem;
39
+ font-weight: bold;
40
+ color: #1C1C1C;
41
+ margin: 0;
42
+ }
43
+ .form-group {
44
+ margin-bottom: 15px;
45
  position: relative;
46
  }
47
+ .form-group label {
48
+ font-size: 0.875rem;
49
+ color: #6C757D;
50
+ margin-bottom: 5px;
51
+ display: block;
 
 
 
 
 
 
 
 
52
  }
53
+ .form-group input,
54
+ .form-group select {
55
+ width: 100%;
56
+ padding: 10px;
57
+ border: 1px solid #E0E0E0;
58
+ border-radius: 10px;
59
+ font-size: 1rem;
60
+ color: #1C1C1C;
61
+ background-color: #FFFFFF;
62
+ box-sizing: border-box;
63
  }
64
+ .form-group input[readonly] {
65
+ background-color: #F5F7FA;
66
+ }
67
+ .change-btn {
68
  position: absolute;
69
  right: 10px;
70
  top: 50%;
71
  transform: translateY(-50%);
72
+ color: #FF0000;
73
+ font-size: 0.75rem;
74
+ font-weight: bold;
 
 
 
 
 
 
 
 
 
 
 
75
  cursor: pointer;
76
+ text-transform: uppercase;
77
+ padding: 2px 5px;
78
+ display: inline-block;
79
  }
80
+ .change-btn.disabled {
81
+ color: #A9A9A9;
82
+ cursor: not-allowed;
83
  }
84
+ .update-btn {
85
+ width: 100%;
86
+ padding: 12px;
87
+ background-color: #FFA07A;
88
+ border-color: #FFA07A;
89
+ color: #6C757D;
90
+ border: 1px solid;
91
+ border-radius: 10px;
92
  font-size: 1rem;
93
+ font-weight: bold;
94
  cursor: pointer;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
95
  margin-top: 20px;
96
  }
97
+ .update-btn:hover {
98
+ background-color: #FF7F50;
99
+ border-color: #FF7F50;
100
+ }
101
+
102
+ /* Media Queries for Smaller Screens */
103
+ @media (max-width: 576px) {
104
+ .container {
105
+ padding: 10px;
106
+ }
107
+ .header h1 {
108
+ font-size: 1.1rem;
109
+ }
110
+ .back-btn svg {
111
+ width: 20px;
112
+ height: 20px;
113
+ }
114
+ .form-group input,
115
+ .form-group select {
116
+ font-size: 0.9rem;
117
+ padding: 8px;
118
+ }
119
+ .update-btn {
120
+ padding: 10px;
121
+ font-size: 0.9rem;
122
+ }
123
  }
124
  </style>
125
  <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
126
  <script>
127
+ function enableEditField(fieldId, flagId) {
128
  var field = document.getElementById(fieldId);
129
+ var flagField = document.getElementById(flagId);
130
+ var changeBtn = $(field).siblings('.change-btn');
131
+ changeBtn.hide();
132
+ if (flagField.value === "false") {
133
+ field.removeAttribute("readonly");
134
+ field.focus();
135
+ $(field).on('input', function() {
136
+ flagField.value = "true";
137
+ });
138
+ }
139
+ }
140
+ function onFocusNext(inputField) {
141
+ var changeBtn = $(inputField).siblings('.change-btn');
142
+ changeBtn.show();
143
  }
 
144
  function updateProfile(event) {
145
  event.preventDefault();
146
+ var phone = $('#phone').val().trim();
147
+ var email = $('#email').val().trim();
148
+ var referralCode = $('#referralCode').val().trim();
149
+ if (!phone && !email && !referralCode) {
150
+ alert("Please enter at least one field to update (Phone, Email, or Referral Code).");
151
+ return;
152
+ }
153
+ if (phone && !/^\d{10}$/.test(phone)) {
154
+ alert("Please enter a valid 10-digit phone number.");
155
+ return;
156
+ }
157
+ if (email && !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)) {
158
+ alert("Please enter a valid email address.");
159
+ return;
160
+ }
161
  var formData = $('#profileForm').serialize();
 
162
  $.ajax({
163
  type: "POST",
164
+ url: "/user/update_profile",
165
  data: formData,
166
+ dataType: 'json',
167
  success: function(response) {
168
  if (response.status === "success") {
169
+ alert(response.message || "Profile updated successfully!");
170
  location.reload();
171
  } else {
172
+ alert(response.message || "Failed to update profile.");
173
  }
174
  },
175
+ error: function(xhr, status, error) {
176
+ console.error("Error:", error);
177
+ alert("An error occurred while updating the profile. Please try again.");
178
  }
179
  });
180
  }
181
+ $(document).ready(function() {
182
+ if ($('#nameEdited').val() === "true") {
183
+ $('#customerName').siblings('.change-btn').addClass('disabled').off('click');
184
+ }
185
+ if ($('#phoneEdited').val() === "true") {
186
+ $('#phone').siblings('.change-btn').addClass('disabled').off('click');
187
+ }
188
+ if ($('#emailEdited').val() === "true") {
189
+ $('#email').siblings('.change-btn').addClass('disabled').off('click');
190
+ }
191
+ });
 
 
 
 
 
192
  </script>
193
  </head>
194
  <body>
195
+ <div class="container">
196
+ <div class="header">
197
+ <a href="/menu" class="back-btn">
198
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
199
+ <path d="M15 18l-6-6 6-6"/>
200
+ </svg>
201
+ </a>
202
+ <h1>Your Profile</h1>
203
+ </div>
 
 
 
 
 
 
 
 
 
 
 
204
 
205
+ <form id="profileForm" method="POST" onsubmit="updateProfile(event)">
206
+ <input type="hidden" id="nameEdited" name="nameEdited" value="{{ 'true' if customer['name_edited'] else 'false' }}">
207
+ <input type="hidden" id="phoneEdited" name="phoneEdited" value="{{ 'true' if customer['phone_edited'] else 'false' }}">
208
+ <input type="hidden" id="emailEdited" name="emailEdited" value="{{ 'true' if customer['email_edited'] else 'false' }}">
 
 
209
 
210
+ <div class="form-group">
211
+ <label for="customerName">Name</label>
212
+ <input type="text" id="customerName" name="customerName" value="{{ customer['name'] }}" readonly>
213
+ <span class="change-btn" onclick="enableEditField('customerName', 'nameEdited')">CHANGE</span>
214
+ </div>
 
215
 
216
+ <div class="form-group">
217
+ <label for="phone">Mobile</label>
218
+ <input type="text" id="phone" name="phone" value="{{ customer['phone'] }}" readonly onfocus="onFocusNext(this)">
219
+ <span class="change-btn" onclick="enableEditField('phone', 'phoneEdited')">CHANGE</span>
220
+ </div>
 
 
221
 
222
+ <div class="form-group">
223
+ <label for="email">Email</label>
224
+ <input type="email" id="email" name="email" value="{{ customer['email'] }}" readonly onfocus="onFocusNext(this)">
225
+ <span class="change-btn" onclick="enableEditField('email', 'emailEdited')">CHANGE</span>
226
+ </div>
227
 
228
+ <div class="form-group">
229
+ <label for="referralCode">Referral Code</label>
230
+ <input type="text" id="referralCode" name="referralCode" value="{{ customer['referral_code'] }}">
 
 
 
231
  </div>
 
232
 
233
+ <button type="submit" class="update-btn">Update profile</button>
234
+ </form>
235
  </div>
236
  </body>
237
+ </html>