@phygitallabs/phygital-consent 1.0.7 → 1.0.9

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,19 @@ 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
- flex: 1,
165
- minWidth: 0,
166
189
  borderRadius: "0.5rem",
167
- background: "#111827",
190
+ border: "1px solid #111827",
191
+ background: "#fff",
168
192
  padding: "0.5rem 1rem",
169
193
  fontSize: "0.875rem",
170
194
  fontWeight: 500,
171
- color: "#fff",
172
- border: "none",
195
+ color: "#111827",
173
196
  cursor: "pointer",
174
197
  }}
175
198
  >
176
- Bỏ qua
199
+ Từ chối
177
200
  </button>
178
201
  <button
179
202
  type="button"
@@ -224,7 +247,7 @@ export function PolicyPopup({
224
247
  backgroundColor: "rgba(0,0,0,0.5)",
225
248
  padding: "1rem",
226
249
  }}
227
- onClick={(e) => e.target === e.currentTarget && handleRefusalAck()}
250
+ onClick={(e) => e.target === e.currentTarget && handleBackToPolicy()}
228
251
  >
229
252
  <div
230
253
  className="consent:bg-white consent:rounded-xl consent:border consent:border-gray-200 consent:shadow-lg"
@@ -250,24 +273,59 @@ export function PolicyPopup({
250
273
  >
251
274
  {REFUSAL_MESSAGE}
252
275
  </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"
276
+ <div
257
277
  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%",
278
+ display: "flex",
279
+ gap: "0.5rem",
280
+ flexWrap: "wrap",
267
281
  }}
268
282
  >
269
- Tôi đã hiểu
270
- </button>
283
+ <button
284
+ type="button"
285
+ onClick={handleBackToPolicy}
286
+ 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"
287
+ style={{
288
+ borderRadius: "0.5rem",
289
+ border: "1px solid #111827",
290
+ background: "#fff",
291
+ padding: "0.5rem 1rem",
292
+ fontSize: "0.875rem",
293
+ fontWeight: 500,
294
+ color: "#111827",
295
+ cursor: "pointer",
296
+ }}
297
+ >
298
+ Trở lại
299
+ </button>
300
+ <button
301
+ type="button"
302
+ onClick={handleConfirmReject}
303
+ disabled={createUserConsent.isPending}
304
+ 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"
305
+ style={{
306
+ flex: 1,
307
+ minWidth: 0,
308
+ borderRadius: "0.5rem",
309
+ background: "#111827",
310
+ padding: "0.5rem 1rem",
311
+ fontSize: "0.875rem",
312
+ fontWeight: 500,
313
+ color: "#fff",
314
+ border: "none",
315
+ cursor: "pointer",
316
+ }}
317
+ >
318
+ Tiếp tục
319
+ </button>
320
+ </div>
321
+ {createUserConsent.isError && (
322
+ <p
323
+ className="consent:text-sm consent:text-red-600"
324
+ style={{ fontSize: "0.875rem", color: "#dc2626", margin: "0.5rem 0 0 0" }}
325
+ >
326
+ Đã xảy ra lỗi. Vui lòng thử lại.
327
+ </p>
328
+ )}
271
329
  </div>
272
330
  </div>
273
331
  )}
@@ -90,6 +90,7 @@ export const ConsentServiceProvider: React.FC<ConsentServiceProviderProps> = ({
90
90
  requestInterceptors = {},
91
91
  responseInterceptors = {},
92
92
  }) => {
93
+
93
94
  const queryClientInstance = useMemo(
94
95
  () =>
95
96
  queryClient ||
@@ -100,6 +101,7 @@ export const ConsentServiceProvider: React.FC<ConsentServiceProviderProps> = ({
100
101
  refetchOnMount: false,
101
102
  refetchOnReconnect: false,
102
103
  ...queryClientConfig?.defaultOptions?.queries,
104
+ retry: 0,
103
105
  },
104
106
  mutations: {
105
107
  ...queryClientConfig?.defaultOptions?.mutations,