@phygitallabs/phygital-consent 1.0.8 → 1.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -81,7 +81,7 @@ export function CookieConsentBanner({
81
81
  createConsent.mutate({
82
82
  device_id: deviceId,
83
83
  status: "REJECTED",
84
- selected_preferences: [],
84
+ selected_preferences: ["essential"],
85
85
  });
86
86
  };
87
87
 
@@ -98,7 +98,7 @@ export function CookieConsentBanner({
98
98
  createConsent.mutate({
99
99
  device_id: deviceId,
100
100
  status: "ACCEPTED",
101
- selected_preferences: selected.length > 0 ? selected : [],
101
+ selected_preferences: selected.length > 0 ? selected : ["essential"],
102
102
  });
103
103
  };
104
104
 
@@ -28,8 +28,8 @@ export function PolicyPopup({
28
28
  const [showRefusalAlert, setShowRefusalAlert] = useState(false);
29
29
 
30
30
  const createUserConsent = useCreateUserConsent({
31
- onSuccess: () => {
32
- onAgreeSuccess?.();
31
+ onSuccess: (_data, variables) => {
32
+ if (variables.status === "ACCEPTED") onAgreeSuccess?.();
33
33
  handleClose();
34
34
  },
35
35
  });
@@ -44,9 +44,15 @@ export function PolicyPopup({
44
44
  setShowRefusalAlert(true);
45
45
  };
46
46
 
47
- const handleRefusalAck = () => {
47
+ const handleBackToPolicy = () => {
48
48
  setShowRefusalAlert(false);
49
- onClose();
49
+ };
50
+
51
+ const handleConfirmReject = () => {
52
+ createUserConsent.mutate({
53
+ user_id: userId,
54
+ status: "REJECTED",
55
+ });
50
56
  };
51
57
 
52
58
  const handleAgree = () => {
@@ -91,17 +97,37 @@ export function PolicyPopup({
91
97
  overflow: "hidden",
92
98
  display: "flex",
93
99
  flexDirection: "column",
100
+ position: "relative",
94
101
  }}
95
102
  onClick={(e) => e.stopPropagation()}
96
103
  >
104
+ <button
105
+ type="button"
106
+ onClick={handleClose}
107
+ aria-label="Đóng"
108
+ style={{
109
+ position: "absolute",
110
+ top: "1rem",
111
+ right: "1rem",
112
+ width: "2rem",
113
+ height: "2rem",
114
+ borderRadius: "0.25rem",
115
+ border: "none",
116
+ background: "transparent",
117
+ cursor: "pointer",
118
+ fontSize: "1.25rem",
119
+ lineHeight: 1,
120
+ color: "#6b7280",
121
+ }}
122
+ >
123
+ ×
124
+ </button>
97
125
  <h2
98
- className="consent:text-lg consent:font-semibold consent:text-gray-900"
99
126
  style={{
100
- fontSize: "1.125rem",
127
+ fontSize: "18px",
101
128
  fontWeight: 600,
102
- color: "#2563eb",
103
- padding: "1rem 1.25rem",
104
- borderBottom: "1px solid #e5e7eb",
129
+ color: "#000",
130
+ padding: "20px 2.5rem 12px 20px",
105
131
  }}
106
132
  >
107
133
  Chính sách bảo mật
@@ -122,8 +148,7 @@ export function PolicyPopup({
122
148
  </div>
123
149
  <div
124
150
  style={{
125
- padding: "1rem 1.25rem",
126
- borderTop: "1px solid #e5e7eb",
151
+ padding: "1rem 1.25rem 1.25rem 1.25rem",
127
152
  display: "flex",
128
153
  flexDirection: "column",
129
154
  gap: "1rem",
@@ -159,21 +184,20 @@ export function PolicyPopup({
159
184
  type="button"
160
185
  onClick={handleRefuse}
161
186
  disabled={createUserConsent.isPending}
162
- className="consent:rounded-lg consent:bg-gray-900 consent:px-4 consent:py-2 consent:text-sm consent:font-medium consent:text-white consent:shadow-sm hover:consent:bg-gray-800 disabled:consent:opacity-50"
187
+ className="consent:rounded-lg consent:border consent:border-gray-300 consent:bg-white consent:px-4 consent:py-2 consent:text-sm consent:font-medium consent:text-gray-700 consent:shadow-sm hover:consent:bg-gray-50 disabled:consent:opacity-50"
163
188
  style={{
164
189
  flex: 1,
165
- minWidth: 0,
166
190
  borderRadius: "0.5rem",
167
- background: "#111827",
191
+ border: "1px solid #111827",
192
+ background: "#fff",
168
193
  padding: "0.5rem 1rem",
169
194
  fontSize: "0.875rem",
170
195
  fontWeight: 500,
171
- color: "#fff",
172
- border: "none",
196
+ color: "#111827",
173
197
  cursor: "pointer",
174
198
  }}
175
199
  >
176
- Bỏ qua
200
+ Từ chối
177
201
  </button>
178
202
  <button
179
203
  type="button"
@@ -224,7 +248,7 @@ export function PolicyPopup({
224
248
  backgroundColor: "rgba(0,0,0,0.5)",
225
249
  padding: "1rem",
226
250
  }}
227
- onClick={(e) => e.target === e.currentTarget && handleRefusalAck()}
251
+ onClick={(e) => e.target === e.currentTarget && handleBackToPolicy()}
228
252
  >
229
253
  <div
230
254
  className="consent:bg-white consent:rounded-xl consent:border consent:border-gray-200 consent:shadow-lg"
@@ -250,24 +274,60 @@ export function PolicyPopup({
250
274
  >
251
275
  {REFUSAL_MESSAGE}
252
276
  </p>
253
- <button
254
- type="button"
255
- onClick={handleRefusalAck}
256
- className="consent:rounded-lg consent:bg-gray-900 consent:px-4 consent:py-2 consent:text-sm consent:font-medium consent:text-white consent:w-full"
277
+ <div
257
278
  style={{
258
- borderRadius: "0.5rem",
259
- background: "#111827",
260
- padding: "0.5rem 1rem",
261
- fontSize: "0.875rem",
262
- fontWeight: 500,
263
- color: "#fff",
264
- border: "none",
265
- cursor: "pointer",
266
- width: "100%",
279
+ display: "flex",
280
+ gap: "0.5rem",
281
+ flexWrap: "wrap",
267
282
  }}
268
283
  >
269
- Tôi đã hiểu
270
- </button>
284
+ <button
285
+ type="button"
286
+ onClick={handleBackToPolicy}
287
+ className="consent:rounded-lg consent:border consent:border-gray-300 consent:bg-white consent:px-4 consent:py-2 consent:text-sm consent:font-medium consent:text-gray-700 consent:shadow-sm hover:consent:bg-gray-50 disabled:consent:opacity-50"
288
+ style={{
289
+ flex: 1,
290
+ borderRadius: "0.5rem",
291
+ border: "1px solid #111827",
292
+ background: "#fff",
293
+ padding: "0.5rem 1rem",
294
+ fontSize: "0.875rem",
295
+ fontWeight: 500,
296
+ color: "#111827",
297
+ cursor: "pointer",
298
+ }}
299
+ >
300
+ Trở lại
301
+ </button>
302
+ <button
303
+ type="button"
304
+ onClick={handleConfirmReject}
305
+ disabled={createUserConsent.isPending}
306
+ className="consent:rounded-lg consent:bg-gray-900 consent:px-4 consent:py-2 consent:text-sm consent:font-medium consent:text-white consent:shadow-sm disabled:consent:opacity-50 consent:flex-1"
307
+ style={{
308
+ flex: 1,
309
+ minWidth: 0,
310
+ borderRadius: "0.5rem",
311
+ background: "#111827",
312
+ padding: "0.5rem 1rem",
313
+ fontSize: "0.875rem",
314
+ fontWeight: 500,
315
+ color: "#fff",
316
+ border: "none",
317
+ cursor: "pointer",
318
+ }}
319
+ >
320
+ Tiếp tục
321
+ </button>
322
+ </div>
323
+ {createUserConsent.isError && (
324
+ <p
325
+ className="consent:text-sm consent:text-red-600"
326
+ style={{ fontSize: "0.875rem", color: "#dc2626", margin: "0.5rem 0 0 0" }}
327
+ >
328
+ Đã xảy ra lỗi. Vui lòng thử lại.
329
+ </p>
330
+ )}
271
331
  </div>
272
332
  </div>
273
333
  )}