@myrjfa/state 1.1.1 → 1.1.2
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.
- package/dist/index.d.ts +18 -18
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +18 -18
- package/dist/lib/actions/actions.d.ts +189 -170
- package/dist/lib/actions/actions.d.ts.map +1 -1
- package/dist/lib/actions/actions.js +347 -307
- package/dist/lib/actions/auth.d.ts +12 -2
- package/dist/lib/actions/auth.d.ts.map +1 -1
- package/dist/lib/actions/fetcher.d.ts +0 -3
- package/dist/lib/actions/fetcher.d.ts.map +1 -1
- package/dist/lib/actions/fetcher.js +122 -84
- package/dist/lib/actions/{severActions.d.ts → serverActions.d.ts} +1 -1
- package/dist/lib/actions/serverActions.d.ts.map +1 -0
- package/dist/lib/actions/{severActions.js → serverActions.js} +3 -0
- package/dist/lib/authSessionManager.d.ts.map +1 -1
- package/dist/lib/authSessionManager.js +41 -34
- package/dist/lib/context/ChatContext.d.ts +1 -1
- package/dist/lib/context/ChatContext.d.ts.map +1 -1
- package/dist/lib/context/ChatContext.js +338 -338
- package/dist/lib/models/blog.d.ts +3 -2
- package/dist/lib/models/blog.d.ts.map +1 -1
- package/dist/lib/models/{notfications.d.ts → notifications.d.ts} +94 -94
- package/dist/lib/models/notifications.d.ts.map +1 -0
- package/dist/lib/models/opportunities/freelance.d.ts +48 -20
- package/dist/lib/models/opportunities/freelance.d.ts.map +1 -1
- package/dist/lib/models/opportunities/internship.d.ts +48 -20
- package/dist/lib/models/opportunities/internship.d.ts.map +1 -1
- package/dist/lib/models/opportunities/job.d.ts +58 -30
- package/dist/lib/models/opportunities/job.d.ts.map +1 -1
- package/dist/lib/models/opportunities/opportunity.d.ts +61 -33
- package/dist/lib/models/opportunities/opportunity.d.ts.map +1 -1
- package/dist/lib/models/opportunities/opportunity.js +1 -0
- package/dist/lib/models/opportunities/volunteerJob.d.ts +48 -20
- package/dist/lib/models/opportunities/volunteerJob.d.ts.map +1 -1
- package/dist/lib/models/portfolio.d.ts +42 -42
- package/dist/lib/models/props.d.ts +21 -4
- package/dist/lib/models/props.d.ts.map +1 -1
- package/dist/lib/models/tile.d.ts +28 -28
- package/dist/lib/models/user.d.ts +19 -4
- package/dist/lib/models/user.d.ts.map +1 -1
- package/dist/lib/models/user.js +5 -0
- package/dist/lib/userAtom.d.ts +218 -198
- package/dist/lib/userAtom.d.ts.map +1 -1
- package/dist/lib/userAtom.js +129 -127
- package/dist/lib/utils.js +4 -4
- package/package.json +3 -1
- package/dist/lib/actions/property.d.ts +0 -77
- package/dist/lib/actions/property.d.ts.map +0 -1
- package/dist/lib/actions/property.js +0 -133
- package/dist/lib/actions/severActions.d.ts.map +0 -1
- package/dist/lib/actions.d.ts +0 -141
- package/dist/lib/actions.d.ts.map +0 -1
- package/dist/lib/actions.js +0 -307
- package/dist/lib/auth.d.ts +0 -150
- package/dist/lib/auth.d.ts.map +0 -1
- package/dist/lib/auth.js +0 -125
- package/dist/lib/fetcher.d.ts +0 -9
- package/dist/lib/fetcher.d.ts.map +0 -1
- package/dist/lib/fetcher.js +0 -84
- package/dist/lib/models/notfications.d.ts.map +0 -1
- package/dist/lib/models/property.d.ts +0 -79
- package/dist/lib/models/property.d.ts.map +0 -1
- package/dist/lib/models/property.js +0 -134
- package/dist/lib/models/volunteerJob.d.ts +0 -398
- package/dist/lib/models/volunteerJob.d.ts.map +0 -1
- package/dist/lib/models/volunteerJob.js +0 -152
- package/dist/lib/severActions.d.ts +0 -3
- package/dist/lib/severActions.d.ts.map +0 -1
- package/dist/lib/severActions.js +0 -19
- package/dist/lib/socket.d.ts +0 -7
- package/dist/lib/socket.d.ts.map +0 -1
- package/dist/lib/socket.js +0 -22
- /package/dist/lib/models/{notfications.js → notifications.js} +0 -0
|
@@ -1,307 +1,347 @@
|
|
|
1
|
-
import { del, get, patch, post } from "./fetcher";
|
|
2
|
-
// host
|
|
3
|
-
// user/host
|
|
4
|
-
export async function getCurrentUser() {
|
|
5
|
-
try {
|
|
6
|
-
const endpoint = `/users/me`;
|
|
7
|
-
const data = await get(endpoint);
|
|
8
|
-
// console.log(data.message);
|
|
9
|
-
return data?.data;
|
|
10
|
-
}
|
|
11
|
-
catch (error) {
|
|
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
|
-
return {
|
|
141
|
-
success: true,
|
|
142
|
-
reviews:
|
|
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
|
-
const
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
const
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
message: data.message,
|
|
221
|
-
};
|
|
222
|
-
}
|
|
223
|
-
catch (error) {
|
|
224
|
-
console.error('Failed to get reviews: ', error);
|
|
225
|
-
return {
|
|
226
|
-
success: false,
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
export async function
|
|
233
|
-
try {
|
|
234
|
-
const endpoint = `/
|
|
235
|
-
const data = await
|
|
236
|
-
return {
|
|
237
|
-
success: true,
|
|
238
|
-
message: data.message,
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
const
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
}
|
|
1
|
+
import { del, get, patch, post } from "./fetcher";
|
|
2
|
+
// host
|
|
3
|
+
// user/host
|
|
4
|
+
export async function getCurrentUser() {
|
|
5
|
+
try {
|
|
6
|
+
const endpoint = `/users/me`;
|
|
7
|
+
const data = await get(endpoint);
|
|
8
|
+
// console.log(data.message);
|
|
9
|
+
return data?.data;
|
|
10
|
+
}
|
|
11
|
+
catch (error) {
|
|
12
|
+
if (error && typeof error === 'object' && ('$$typeof' in error || error.digest === 'DYNAMIC_SERVER_USAGE')) {
|
|
13
|
+
throw error; // Re-throw Next.js PPR bail-out
|
|
14
|
+
}
|
|
15
|
+
console.error('Failed to fetch user details: ', error);
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export async function userDetails(query, role) {
|
|
20
|
+
try {
|
|
21
|
+
if (role == "admin")
|
|
22
|
+
role = "user";
|
|
23
|
+
const endpoint = `/${role}s/other-${role}/${query}`;
|
|
24
|
+
const data = await get(endpoint);
|
|
25
|
+
return {
|
|
26
|
+
success: true,
|
|
27
|
+
user: data?.data,
|
|
28
|
+
message: data.message
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
if (error && typeof error === 'object' && ('$$typeof' in error || error.digest === 'DYNAMIC_SERVER_USAGE')) {
|
|
33
|
+
throw error; // Re-throw Next.js PPR bail-out
|
|
34
|
+
}
|
|
35
|
+
console.error('Failed to fetch user details: ', error);
|
|
36
|
+
return { success: false, user: null, status: error.status, error: error.message };
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
export async function subscribeToNewsLetter(email) {
|
|
40
|
+
try {
|
|
41
|
+
const endpoint = `/subscription/create`;
|
|
42
|
+
const data = await post(endpoint, { email: email });
|
|
43
|
+
return { success: true, message: data.message };
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
console.error('Error subscribing to newsletter: ', error);
|
|
47
|
+
return {
|
|
48
|
+
success: false,
|
|
49
|
+
error: error.message,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
export async function toggleUserWishlist(slug, tileType) {
|
|
54
|
+
try {
|
|
55
|
+
const endpoint = `/users/fav/${tileType}/toggle`;
|
|
56
|
+
const data = await post(endpoint, { id: slug });
|
|
57
|
+
return { success: true, message: data.message, wishlist: data.data };
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
console.error(`Failed to add ${tileType} to wishlist: `, error);
|
|
61
|
+
return {
|
|
62
|
+
success: false,
|
|
63
|
+
error: error.message,
|
|
64
|
+
wishlist: []
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
// subscribe
|
|
69
|
+
export async function subscribeToCareersPage(email) {
|
|
70
|
+
try {
|
|
71
|
+
const endpoint = `/subscription/create-job`;
|
|
72
|
+
const data = await post(endpoint, { email: email });
|
|
73
|
+
return { success: true, message: data.message };
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
console.error('Error subscribing to newsletter: ', error);
|
|
77
|
+
return {
|
|
78
|
+
success: false,
|
|
79
|
+
error: error.message,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
export async function contactUs(email, name, subject, message) {
|
|
84
|
+
try {
|
|
85
|
+
const endpoint = `/contactUs`;
|
|
86
|
+
const data = await post(endpoint, { email: email, name: name, subject: subject, message: message });
|
|
87
|
+
return { success: true, message: data.message };
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
console.error('Error contacting trippeaze: ', error);
|
|
91
|
+
return {
|
|
92
|
+
success: false,
|
|
93
|
+
error: error.message,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
// resume
|
|
98
|
+
export async function saveUserResume(file) {
|
|
99
|
+
try {
|
|
100
|
+
const endpoint = `/users/resume-update`;
|
|
101
|
+
const formData = new FormData();
|
|
102
|
+
formData.append('resume', file);
|
|
103
|
+
const data = await patch(endpoint, formData);
|
|
104
|
+
return {
|
|
105
|
+
success: true,
|
|
106
|
+
message: data.message,
|
|
107
|
+
user: data.data,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
return { success: false, error: error.message, user: null };
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
export async function getUserContact(username, role) {
|
|
115
|
+
try {
|
|
116
|
+
const endpoint = `/${role}s/getUserContact/${username}`;
|
|
117
|
+
const data = await get(endpoint);
|
|
118
|
+
return {
|
|
119
|
+
success: true,
|
|
120
|
+
message: data.message,
|
|
121
|
+
details: data.data,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
catch (error) {
|
|
125
|
+
return {
|
|
126
|
+
success: false,
|
|
127
|
+
error: error.message,
|
|
128
|
+
details: null,
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
// rating and reviews
|
|
133
|
+
export async function getReviewsById(id, type, options = {}) {
|
|
134
|
+
try {
|
|
135
|
+
const { page = 1, limit = 5, sortBy = 'createdAt', sortOrder = 'desc', rating } = options;
|
|
136
|
+
let endpoint = `/reviews/entity/${id}/${type}?page=${page}&limit=${limit}&sortBy=${sortBy}&sortOrder=${sortOrder}`;
|
|
137
|
+
if (rating)
|
|
138
|
+
endpoint += `&rating=${rating}`;
|
|
139
|
+
const data = await get(endpoint);
|
|
140
|
+
return {
|
|
141
|
+
success: true,
|
|
142
|
+
reviews: data.data.reviews,
|
|
143
|
+
totalCount: data.data.totalCount,
|
|
144
|
+
hasMore: data.data.hasMore,
|
|
145
|
+
message: data.message,
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
catch (error) {
|
|
149
|
+
if (error && typeof error === 'object' && ('$$typeof' in error || error.digest === 'DYNAMIC_SERVER_USAGE')) {
|
|
150
|
+
throw error; // Re-throw Next.js PPR bail-out
|
|
151
|
+
}
|
|
152
|
+
console.error('Failed to get reviews: ', error);
|
|
153
|
+
return {
|
|
154
|
+
success: false,
|
|
155
|
+
reviews: [],
|
|
156
|
+
totalCount: 0,
|
|
157
|
+
hasMore: false,
|
|
158
|
+
error: error.message,
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
export async function getRatingById(id, type) {
|
|
163
|
+
try {
|
|
164
|
+
const endpoint = `/reviews/entity/${id}`;
|
|
165
|
+
const data = await get(endpoint);
|
|
166
|
+
// const data = {
|
|
167
|
+
// data:
|
|
168
|
+
// [{
|
|
169
|
+
// slug: id[0] ?? "",
|
|
170
|
+
// rating: truncateDecimal(sampleReviews.reduce((acc, review) => acc + review.rating, 0) / sampleReviews.length, 1),
|
|
171
|
+
// ratingCount: sampleReviews.length,
|
|
172
|
+
// reviewCount: 100,
|
|
173
|
+
// }],
|
|
174
|
+
// message: "success"
|
|
175
|
+
// }
|
|
176
|
+
return {
|
|
177
|
+
success: true,
|
|
178
|
+
ratings: data.data,
|
|
179
|
+
message: data.message,
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
catch (error) {
|
|
183
|
+
if (error && typeof error === 'object' && ('$$typeof' in error || error.digest === 'DYNAMIC_SERVER_USAGE')) {
|
|
184
|
+
throw error; // Re-throw Next.js PPR bail-out
|
|
185
|
+
}
|
|
186
|
+
console.error('Failed to get reviews: ', error);
|
|
187
|
+
return {
|
|
188
|
+
success: false,
|
|
189
|
+
ratings: [],
|
|
190
|
+
error: error.message,
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
export async function addReview(id, type, formData) {
|
|
195
|
+
try {
|
|
196
|
+
const endpoint = `/reviews/`;
|
|
197
|
+
const data = await post(endpoint, { reviewee: id, revieweeType: type, rating: formData.rating, comment: formData.comment });
|
|
198
|
+
return {
|
|
199
|
+
success: true,
|
|
200
|
+
review: data.data,
|
|
201
|
+
message: data.message,
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
catch (error) {
|
|
205
|
+
console.error('Failed to get reviews: ', error);
|
|
206
|
+
return {
|
|
207
|
+
success: false,
|
|
208
|
+
review: null,
|
|
209
|
+
error: error.message,
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
export async function editReview(id, formData) {
|
|
214
|
+
try {
|
|
215
|
+
const endpoint = `/reviews/${id}`;
|
|
216
|
+
const data = await patch(endpoint, { rating: formData.rating, comment: formData.comment });
|
|
217
|
+
return {
|
|
218
|
+
success: true,
|
|
219
|
+
review: data.data,
|
|
220
|
+
message: data.message,
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
catch (error) {
|
|
224
|
+
console.error('Failed to get reviews: ', error);
|
|
225
|
+
return {
|
|
226
|
+
success: false,
|
|
227
|
+
review: null,
|
|
228
|
+
error: error.message,
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
export async function deleteReview(id) {
|
|
233
|
+
try {
|
|
234
|
+
const endpoint = `/reviews/${id}`;
|
|
235
|
+
const data = await del(endpoint);
|
|
236
|
+
return {
|
|
237
|
+
success: true,
|
|
238
|
+
message: data.message,
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
catch (error) {
|
|
242
|
+
console.error('Failed to get reviews: ', error);
|
|
243
|
+
return {
|
|
244
|
+
success: false,
|
|
245
|
+
error: error.message,
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
// notifications
|
|
250
|
+
export async function getAllNotifications() {
|
|
251
|
+
try {
|
|
252
|
+
const endpoint = `/notification?all=true`;
|
|
253
|
+
const data = await get(endpoint);
|
|
254
|
+
return {
|
|
255
|
+
success: true,
|
|
256
|
+
message: data.message,
|
|
257
|
+
notifs: data.data.notifications,
|
|
258
|
+
unreadCount: data.data.unreadCount,
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
catch (error) {
|
|
262
|
+
console.error('Failed to fetch notifications: ', error);
|
|
263
|
+
return {
|
|
264
|
+
success: false,
|
|
265
|
+
error: error.message,
|
|
266
|
+
notifs: [],
|
|
267
|
+
unreadCount: 0,
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
export async function getNotifications(limit) {
|
|
272
|
+
try {
|
|
273
|
+
const endpoint = `/notification?limit=${limit}`;
|
|
274
|
+
const data = await get(endpoint);
|
|
275
|
+
return {
|
|
276
|
+
success: true,
|
|
277
|
+
message: data.message,
|
|
278
|
+
notifs: data.data.notifications,
|
|
279
|
+
unreadCount: data.data.unreadCount,
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
catch (error) {
|
|
283
|
+
console.error('Failed to fetch notifications: ', error);
|
|
284
|
+
return {
|
|
285
|
+
success: false,
|
|
286
|
+
error: error.message,
|
|
287
|
+
notifs: [],
|
|
288
|
+
unreadCount: 0,
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
export async function toggleNotification(id, read) {
|
|
293
|
+
try {
|
|
294
|
+
const endpoint = `/notification/${id}`;
|
|
295
|
+
const data = await patch(endpoint, { isRead: read });
|
|
296
|
+
return {
|
|
297
|
+
success: true,
|
|
298
|
+
message: data.message,
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
catch (error) {
|
|
302
|
+
console.error('Failed to toggle notification: ', error);
|
|
303
|
+
return {
|
|
304
|
+
success: false,
|
|
305
|
+
error: error.message,
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
export async function toggleAllNotification(read) {
|
|
310
|
+
try {
|
|
311
|
+
const endpoint = `/notification/update/all`;
|
|
312
|
+
const data = await patch(endpoint, { isRead: read });
|
|
313
|
+
return {
|
|
314
|
+
success: true,
|
|
315
|
+
message: data.message,
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
catch (error) {
|
|
319
|
+
console.error('Failed to toggle all notifications: ', error);
|
|
320
|
+
return {
|
|
321
|
+
success: false,
|
|
322
|
+
error: error.message,
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
// #5 — Call button usage alert
|
|
327
|
+
export async function callAlert(payload) {
|
|
328
|
+
try {
|
|
329
|
+
await post(`/users/call-alert`, payload);
|
|
330
|
+
}
|
|
331
|
+
catch {
|
|
332
|
+
// Non-fatal — silently ignore
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
// #6 — Opportunity/Package interest request
|
|
336
|
+
export async function submitInterestRequest(data) {
|
|
337
|
+
try {
|
|
338
|
+
const endpoint = data.type === 'opportunity'
|
|
339
|
+
? '/newHostPost/interest'
|
|
340
|
+
: '/packages/interest';
|
|
341
|
+
await post(endpoint, data);
|
|
342
|
+
return { success: true };
|
|
343
|
+
}
|
|
344
|
+
catch (error) {
|
|
345
|
+
return { success: false, error: error.message };
|
|
346
|
+
}
|
|
347
|
+
}
|