hey-pharmacist-ecommerce 1.0.6 → 1.0.8
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/README.md +53 -19
- package/dist/index.js +469 -40
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +469 -40
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/providers/EcommerceProvider.tsx +5 -2
package/dist/index.mjs
CHANGED
|
@@ -6347,6 +6347,318 @@ var ShippingApi = class extends BaseAPI {
|
|
|
6347
6347
|
return ShippingApiFp(this.configuration).updateZone(body, zoneId, options).then((request) => request(this.axios, this.basePath));
|
|
6348
6348
|
}
|
|
6349
6349
|
};
|
|
6350
|
+
var WishlistApiAxiosParamCreator = function(configuration) {
|
|
6351
|
+
return {
|
|
6352
|
+
/**
|
|
6353
|
+
*
|
|
6354
|
+
* @summary Add product to wishlist
|
|
6355
|
+
* @param {string} productId
|
|
6356
|
+
* @param {*} [options] Override http request option.
|
|
6357
|
+
* @throws {RequiredError}
|
|
6358
|
+
*/
|
|
6359
|
+
addToWishlist: async (productId, options = {}) => {
|
|
6360
|
+
if (productId === null || productId === void 0) {
|
|
6361
|
+
throw new RequiredError("productId", "Required parameter productId was null or undefined when calling addToWishlist.");
|
|
6362
|
+
}
|
|
6363
|
+
const localVarPath = `/wishlist/add/{productId}`.replace(`{${"productId"}}`, encodeURIComponent(String(productId)));
|
|
6364
|
+
const localVarUrlObj = new URL(localVarPath, "https://example.com");
|
|
6365
|
+
let baseOptions;
|
|
6366
|
+
if (configuration) {
|
|
6367
|
+
baseOptions = configuration.baseOptions;
|
|
6368
|
+
}
|
|
6369
|
+
const localVarRequestOptions = { method: "POST", ...baseOptions, ...options };
|
|
6370
|
+
const localVarHeaderParameter = {};
|
|
6371
|
+
const localVarQueryParameter = {};
|
|
6372
|
+
if (configuration && configuration.accessToken) {
|
|
6373
|
+
const accessToken = typeof configuration.accessToken === "function" ? await configuration.accessToken() : await configuration.accessToken;
|
|
6374
|
+
localVarHeaderParameter["Authorization"] = "Bearer " + accessToken;
|
|
6375
|
+
}
|
|
6376
|
+
const query = new URLSearchParams(localVarUrlObj.search);
|
|
6377
|
+
for (const key in localVarQueryParameter) {
|
|
6378
|
+
query.set(key, localVarQueryParameter[key]);
|
|
6379
|
+
}
|
|
6380
|
+
for (const key in options.params) {
|
|
6381
|
+
query.set(key, options.params[key]);
|
|
6382
|
+
}
|
|
6383
|
+
localVarUrlObj.search = new URLSearchParams(query).toString();
|
|
6384
|
+
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
|
|
6385
|
+
localVarRequestOptions.headers = { ...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers };
|
|
6386
|
+
return {
|
|
6387
|
+
url: localVarUrlObj.pathname + localVarUrlObj.search + localVarUrlObj.hash,
|
|
6388
|
+
options: localVarRequestOptions
|
|
6389
|
+
};
|
|
6390
|
+
},
|
|
6391
|
+
/**
|
|
6392
|
+
*
|
|
6393
|
+
* @summary Clear wishlist
|
|
6394
|
+
* @param {*} [options] Override http request option.
|
|
6395
|
+
* @throws {RequiredError}
|
|
6396
|
+
*/
|
|
6397
|
+
clearWishlist: async (options = {}) => {
|
|
6398
|
+
const localVarPath = `/wishlist/clear`;
|
|
6399
|
+
const localVarUrlObj = new URL(localVarPath, "https://example.com");
|
|
6400
|
+
let baseOptions;
|
|
6401
|
+
if (configuration) {
|
|
6402
|
+
baseOptions = configuration.baseOptions;
|
|
6403
|
+
}
|
|
6404
|
+
const localVarRequestOptions = { method: "DELETE", ...baseOptions, ...options };
|
|
6405
|
+
const localVarHeaderParameter = {};
|
|
6406
|
+
const localVarQueryParameter = {};
|
|
6407
|
+
if (configuration && configuration.accessToken) {
|
|
6408
|
+
const accessToken = typeof configuration.accessToken === "function" ? await configuration.accessToken() : await configuration.accessToken;
|
|
6409
|
+
localVarHeaderParameter["Authorization"] = "Bearer " + accessToken;
|
|
6410
|
+
}
|
|
6411
|
+
const query = new URLSearchParams(localVarUrlObj.search);
|
|
6412
|
+
for (const key in localVarQueryParameter) {
|
|
6413
|
+
query.set(key, localVarQueryParameter[key]);
|
|
6414
|
+
}
|
|
6415
|
+
for (const key in options.params) {
|
|
6416
|
+
query.set(key, options.params[key]);
|
|
6417
|
+
}
|
|
6418
|
+
localVarUrlObj.search = new URLSearchParams(query).toString();
|
|
6419
|
+
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
|
|
6420
|
+
localVarRequestOptions.headers = { ...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers };
|
|
6421
|
+
return {
|
|
6422
|
+
url: localVarUrlObj.pathname + localVarUrlObj.search + localVarUrlObj.hash,
|
|
6423
|
+
options: localVarRequestOptions
|
|
6424
|
+
};
|
|
6425
|
+
},
|
|
6426
|
+
/**
|
|
6427
|
+
*
|
|
6428
|
+
* @summary Get user wishlist
|
|
6429
|
+
* @param {*} [options] Override http request option.
|
|
6430
|
+
* @throws {RequiredError}
|
|
6431
|
+
*/
|
|
6432
|
+
getWishlist: async (options = {}) => {
|
|
6433
|
+
const localVarPath = `/wishlist`;
|
|
6434
|
+
const localVarUrlObj = new URL(localVarPath, "https://example.com");
|
|
6435
|
+
let baseOptions;
|
|
6436
|
+
if (configuration) {
|
|
6437
|
+
baseOptions = configuration.baseOptions;
|
|
6438
|
+
}
|
|
6439
|
+
const localVarRequestOptions = { method: "GET", ...baseOptions, ...options };
|
|
6440
|
+
const localVarHeaderParameter = {};
|
|
6441
|
+
const localVarQueryParameter = {};
|
|
6442
|
+
if (configuration && configuration.accessToken) {
|
|
6443
|
+
const accessToken = typeof configuration.accessToken === "function" ? await configuration.accessToken() : await configuration.accessToken;
|
|
6444
|
+
localVarHeaderParameter["Authorization"] = "Bearer " + accessToken;
|
|
6445
|
+
}
|
|
6446
|
+
const query = new URLSearchParams(localVarUrlObj.search);
|
|
6447
|
+
for (const key in localVarQueryParameter) {
|
|
6448
|
+
query.set(key, localVarQueryParameter[key]);
|
|
6449
|
+
}
|
|
6450
|
+
for (const key in options.params) {
|
|
6451
|
+
query.set(key, options.params[key]);
|
|
6452
|
+
}
|
|
6453
|
+
localVarUrlObj.search = new URLSearchParams(query).toString();
|
|
6454
|
+
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
|
|
6455
|
+
localVarRequestOptions.headers = { ...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers };
|
|
6456
|
+
return {
|
|
6457
|
+
url: localVarUrlObj.pathname + localVarUrlObj.search + localVarUrlObj.hash,
|
|
6458
|
+
options: localVarRequestOptions
|
|
6459
|
+
};
|
|
6460
|
+
},
|
|
6461
|
+
/**
|
|
6462
|
+
*
|
|
6463
|
+
* @summary Get wishlist item count
|
|
6464
|
+
* @param {*} [options] Override http request option.
|
|
6465
|
+
* @throws {RequiredError}
|
|
6466
|
+
*/
|
|
6467
|
+
getWishlistItemCount: async (options = {}) => {
|
|
6468
|
+
const localVarPath = `/wishlist/count`;
|
|
6469
|
+
const localVarUrlObj = new URL(localVarPath, "https://example.com");
|
|
6470
|
+
let baseOptions;
|
|
6471
|
+
if (configuration) {
|
|
6472
|
+
baseOptions = configuration.baseOptions;
|
|
6473
|
+
}
|
|
6474
|
+
const localVarRequestOptions = { method: "GET", ...baseOptions, ...options };
|
|
6475
|
+
const localVarHeaderParameter = {};
|
|
6476
|
+
const localVarQueryParameter = {};
|
|
6477
|
+
if (configuration && configuration.accessToken) {
|
|
6478
|
+
const accessToken = typeof configuration.accessToken === "function" ? await configuration.accessToken() : await configuration.accessToken;
|
|
6479
|
+
localVarHeaderParameter["Authorization"] = "Bearer " + accessToken;
|
|
6480
|
+
}
|
|
6481
|
+
const query = new URLSearchParams(localVarUrlObj.search);
|
|
6482
|
+
for (const key in localVarQueryParameter) {
|
|
6483
|
+
query.set(key, localVarQueryParameter[key]);
|
|
6484
|
+
}
|
|
6485
|
+
for (const key in options.params) {
|
|
6486
|
+
query.set(key, options.params[key]);
|
|
6487
|
+
}
|
|
6488
|
+
localVarUrlObj.search = new URLSearchParams(query).toString();
|
|
6489
|
+
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
|
|
6490
|
+
localVarRequestOptions.headers = { ...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers };
|
|
6491
|
+
return {
|
|
6492
|
+
url: localVarUrlObj.pathname + localVarUrlObj.search + localVarUrlObj.hash,
|
|
6493
|
+
options: localVarRequestOptions
|
|
6494
|
+
};
|
|
6495
|
+
},
|
|
6496
|
+
/**
|
|
6497
|
+
*
|
|
6498
|
+
* @summary Remove product from wishlist
|
|
6499
|
+
* @param {string} productId
|
|
6500
|
+
* @param {*} [options] Override http request option.
|
|
6501
|
+
* @throws {RequiredError}
|
|
6502
|
+
*/
|
|
6503
|
+
removeFromWishlist: async (productId, options = {}) => {
|
|
6504
|
+
if (productId === null || productId === void 0) {
|
|
6505
|
+
throw new RequiredError("productId", "Required parameter productId was null or undefined when calling removeFromWishlist.");
|
|
6506
|
+
}
|
|
6507
|
+
const localVarPath = `/wishlist/remove/{productId}`.replace(`{${"productId"}}`, encodeURIComponent(String(productId)));
|
|
6508
|
+
const localVarUrlObj = new URL(localVarPath, "https://example.com");
|
|
6509
|
+
let baseOptions;
|
|
6510
|
+
if (configuration) {
|
|
6511
|
+
baseOptions = configuration.baseOptions;
|
|
6512
|
+
}
|
|
6513
|
+
const localVarRequestOptions = { method: "DELETE", ...baseOptions, ...options };
|
|
6514
|
+
const localVarHeaderParameter = {};
|
|
6515
|
+
const localVarQueryParameter = {};
|
|
6516
|
+
if (configuration && configuration.accessToken) {
|
|
6517
|
+
const accessToken = typeof configuration.accessToken === "function" ? await configuration.accessToken() : await configuration.accessToken;
|
|
6518
|
+
localVarHeaderParameter["Authorization"] = "Bearer " + accessToken;
|
|
6519
|
+
}
|
|
6520
|
+
const query = new URLSearchParams(localVarUrlObj.search);
|
|
6521
|
+
for (const key in localVarQueryParameter) {
|
|
6522
|
+
query.set(key, localVarQueryParameter[key]);
|
|
6523
|
+
}
|
|
6524
|
+
for (const key in options.params) {
|
|
6525
|
+
query.set(key, options.params[key]);
|
|
6526
|
+
}
|
|
6527
|
+
localVarUrlObj.search = new URLSearchParams(query).toString();
|
|
6528
|
+
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
|
|
6529
|
+
localVarRequestOptions.headers = { ...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers };
|
|
6530
|
+
return {
|
|
6531
|
+
url: localVarUrlObj.pathname + localVarUrlObj.search + localVarUrlObj.hash,
|
|
6532
|
+
options: localVarRequestOptions
|
|
6533
|
+
};
|
|
6534
|
+
}
|
|
6535
|
+
};
|
|
6536
|
+
};
|
|
6537
|
+
var WishlistApiFp = function(configuration) {
|
|
6538
|
+
return {
|
|
6539
|
+
/**
|
|
6540
|
+
*
|
|
6541
|
+
* @summary Add product to wishlist
|
|
6542
|
+
* @param {string} productId
|
|
6543
|
+
* @param {*} [options] Override http request option.
|
|
6544
|
+
* @throws {RequiredError}
|
|
6545
|
+
*/
|
|
6546
|
+
async addToWishlist(productId, options) {
|
|
6547
|
+
const localVarAxiosArgs = await WishlistApiAxiosParamCreator(configuration).addToWishlist(productId, options);
|
|
6548
|
+
return (axios = globalAxios4, basePath = BASE_PATH) => {
|
|
6549
|
+
const axiosRequestArgs = { ...localVarAxiosArgs.options, url: basePath + localVarAxiosArgs.url };
|
|
6550
|
+
return axios.request(axiosRequestArgs);
|
|
6551
|
+
};
|
|
6552
|
+
},
|
|
6553
|
+
/**
|
|
6554
|
+
*
|
|
6555
|
+
* @summary Clear wishlist
|
|
6556
|
+
* @param {*} [options] Override http request option.
|
|
6557
|
+
* @throws {RequiredError}
|
|
6558
|
+
*/
|
|
6559
|
+
async clearWishlist(options) {
|
|
6560
|
+
const localVarAxiosArgs = await WishlistApiAxiosParamCreator(configuration).clearWishlist(options);
|
|
6561
|
+
return (axios = globalAxios4, basePath = BASE_PATH) => {
|
|
6562
|
+
const axiosRequestArgs = { ...localVarAxiosArgs.options, url: basePath + localVarAxiosArgs.url };
|
|
6563
|
+
return axios.request(axiosRequestArgs);
|
|
6564
|
+
};
|
|
6565
|
+
},
|
|
6566
|
+
/**
|
|
6567
|
+
*
|
|
6568
|
+
* @summary Get user wishlist
|
|
6569
|
+
* @param {*} [options] Override http request option.
|
|
6570
|
+
* @throws {RequiredError}
|
|
6571
|
+
*/
|
|
6572
|
+
async getWishlist(options) {
|
|
6573
|
+
const localVarAxiosArgs = await WishlistApiAxiosParamCreator(configuration).getWishlist(options);
|
|
6574
|
+
return (axios = globalAxios4, basePath = BASE_PATH) => {
|
|
6575
|
+
const axiosRequestArgs = { ...localVarAxiosArgs.options, url: basePath + localVarAxiosArgs.url };
|
|
6576
|
+
return axios.request(axiosRequestArgs);
|
|
6577
|
+
};
|
|
6578
|
+
},
|
|
6579
|
+
/**
|
|
6580
|
+
*
|
|
6581
|
+
* @summary Get wishlist item count
|
|
6582
|
+
* @param {*} [options] Override http request option.
|
|
6583
|
+
* @throws {RequiredError}
|
|
6584
|
+
*/
|
|
6585
|
+
async getWishlistItemCount(options) {
|
|
6586
|
+
const localVarAxiosArgs = await WishlistApiAxiosParamCreator(configuration).getWishlistItemCount(options);
|
|
6587
|
+
return (axios = globalAxios4, basePath = BASE_PATH) => {
|
|
6588
|
+
const axiosRequestArgs = { ...localVarAxiosArgs.options, url: basePath + localVarAxiosArgs.url };
|
|
6589
|
+
return axios.request(axiosRequestArgs);
|
|
6590
|
+
};
|
|
6591
|
+
},
|
|
6592
|
+
/**
|
|
6593
|
+
*
|
|
6594
|
+
* @summary Remove product from wishlist
|
|
6595
|
+
* @param {string} productId
|
|
6596
|
+
* @param {*} [options] Override http request option.
|
|
6597
|
+
* @throws {RequiredError}
|
|
6598
|
+
*/
|
|
6599
|
+
async removeFromWishlist(productId, options) {
|
|
6600
|
+
const localVarAxiosArgs = await WishlistApiAxiosParamCreator(configuration).removeFromWishlist(productId, options);
|
|
6601
|
+
return (axios = globalAxios4, basePath = BASE_PATH) => {
|
|
6602
|
+
const axiosRequestArgs = { ...localVarAxiosArgs.options, url: basePath + localVarAxiosArgs.url };
|
|
6603
|
+
return axios.request(axiosRequestArgs);
|
|
6604
|
+
};
|
|
6605
|
+
}
|
|
6606
|
+
};
|
|
6607
|
+
};
|
|
6608
|
+
var WishlistApi = class extends BaseAPI {
|
|
6609
|
+
/**
|
|
6610
|
+
*
|
|
6611
|
+
* @summary Add product to wishlist
|
|
6612
|
+
* @param {string} productId
|
|
6613
|
+
* @param {*} [options] Override http request option.
|
|
6614
|
+
* @throws {RequiredError}
|
|
6615
|
+
* @memberof WishlistApi
|
|
6616
|
+
*/
|
|
6617
|
+
async addToWishlist(productId, options) {
|
|
6618
|
+
return WishlistApiFp(this.configuration).addToWishlist(productId, options).then((request) => request(this.axios, this.basePath));
|
|
6619
|
+
}
|
|
6620
|
+
/**
|
|
6621
|
+
*
|
|
6622
|
+
* @summary Clear wishlist
|
|
6623
|
+
* @param {*} [options] Override http request option.
|
|
6624
|
+
* @throws {RequiredError}
|
|
6625
|
+
* @memberof WishlistApi
|
|
6626
|
+
*/
|
|
6627
|
+
async clearWishlist(options) {
|
|
6628
|
+
return WishlistApiFp(this.configuration).clearWishlist(options).then((request) => request(this.axios, this.basePath));
|
|
6629
|
+
}
|
|
6630
|
+
/**
|
|
6631
|
+
*
|
|
6632
|
+
* @summary Get user wishlist
|
|
6633
|
+
* @param {*} [options] Override http request option.
|
|
6634
|
+
* @throws {RequiredError}
|
|
6635
|
+
* @memberof WishlistApi
|
|
6636
|
+
*/
|
|
6637
|
+
async getWishlist(options) {
|
|
6638
|
+
return WishlistApiFp(this.configuration).getWishlist(options).then((request) => request(this.axios, this.basePath));
|
|
6639
|
+
}
|
|
6640
|
+
/**
|
|
6641
|
+
*
|
|
6642
|
+
* @summary Get wishlist item count
|
|
6643
|
+
* @param {*} [options] Override http request option.
|
|
6644
|
+
* @throws {RequiredError}
|
|
6645
|
+
* @memberof WishlistApi
|
|
6646
|
+
*/
|
|
6647
|
+
async getWishlistItemCount(options) {
|
|
6648
|
+
return WishlistApiFp(this.configuration).getWishlistItemCount(options).then((request) => request(this.axios, this.basePath));
|
|
6649
|
+
}
|
|
6650
|
+
/**
|
|
6651
|
+
*
|
|
6652
|
+
* @summary Remove product from wishlist
|
|
6653
|
+
* @param {string} productId
|
|
6654
|
+
* @param {*} [options] Override http request option.
|
|
6655
|
+
* @throws {RequiredError}
|
|
6656
|
+
* @memberof WishlistApi
|
|
6657
|
+
*/
|
|
6658
|
+
async removeFromWishlist(productId, options) {
|
|
6659
|
+
return WishlistApiFp(this.configuration).removeFromWishlist(productId, options).then((request) => request(this.axios, this.basePath));
|
|
6660
|
+
}
|
|
6661
|
+
};
|
|
6350
6662
|
|
|
6351
6663
|
// src/lib/Apis/models/manual-order-dto.ts
|
|
6352
6664
|
var ManualOrderDTOOrderStatusEnum = /* @__PURE__ */ ((ManualOrderDTOOrderStatusEnum2) => {
|
|
@@ -6472,6 +6784,162 @@ function CartProvider({ children }) {
|
|
|
6472
6784
|
};
|
|
6473
6785
|
return /* @__PURE__ */ React19.createElement(CartContext.Provider, { value }, children);
|
|
6474
6786
|
}
|
|
6787
|
+
var BaseUrl = "https://api.heypharmacist.com";
|
|
6788
|
+
globalAxios4.interceptors.request.use(async (config) => {
|
|
6789
|
+
if (!config?.headers) {
|
|
6790
|
+
throw new Error(
|
|
6791
|
+
`Expected 'config' and 'config.headers' not to be undefined`
|
|
6792
|
+
);
|
|
6793
|
+
}
|
|
6794
|
+
if (typeof window !== "undefined") {
|
|
6795
|
+
try {
|
|
6796
|
+
const ecommerceConfig = getCurrentConfig();
|
|
6797
|
+
const token = getAuthToken();
|
|
6798
|
+
if (token) {
|
|
6799
|
+
config.headers.Authorization = `Bearer ${token}`;
|
|
6800
|
+
}
|
|
6801
|
+
if (ecommerceConfig?.storeId) {
|
|
6802
|
+
config.headers["X-Store-Key"] = ecommerceConfig.storeId;
|
|
6803
|
+
}
|
|
6804
|
+
} catch (error) {
|
|
6805
|
+
console.warn("API configuration not initialized yet:", error);
|
|
6806
|
+
}
|
|
6807
|
+
}
|
|
6808
|
+
return config;
|
|
6809
|
+
});
|
|
6810
|
+
var ABORT_CONTROLLER = new AbortController();
|
|
6811
|
+
var AXIOS_CONFIG = new Configuration({
|
|
6812
|
+
basePath: BaseUrl,
|
|
6813
|
+
baseOptions: {
|
|
6814
|
+
signal: ABORT_CONTROLLER.signal,
|
|
6815
|
+
timeout: 2e4
|
|
6816
|
+
}
|
|
6817
|
+
});
|
|
6818
|
+
var WishlistContext = createContext(void 0);
|
|
6819
|
+
function WishlistProvider({ children }) {
|
|
6820
|
+
const [state, setState] = useState({
|
|
6821
|
+
_id: "",
|
|
6822
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
6823
|
+
updatedAt: /* @__PURE__ */ new Date(),
|
|
6824
|
+
userId: "",
|
|
6825
|
+
products: []
|
|
6826
|
+
});
|
|
6827
|
+
const { isAuthenticated } = useAuth() || {};
|
|
6828
|
+
const wishlistApi = useMemo(() => new WishlistApi(AXIOS_CONFIG), []);
|
|
6829
|
+
const fetchWishlist = useCallback(async () => {
|
|
6830
|
+
if (!isAuthenticated) {
|
|
6831
|
+
setState((prev) => ({
|
|
6832
|
+
...prev,
|
|
6833
|
+
isLoading: false,
|
|
6834
|
+
products: []
|
|
6835
|
+
}));
|
|
6836
|
+
return;
|
|
6837
|
+
}
|
|
6838
|
+
setState((prev) => ({ ...prev, isLoading: true, error: null }));
|
|
6839
|
+
try {
|
|
6840
|
+
const response = await wishlistApi.getWishlist();
|
|
6841
|
+
const responseData = response?.data;
|
|
6842
|
+
setState({
|
|
6843
|
+
_id: responseData._id,
|
|
6844
|
+
createdAt: responseData.createdAt,
|
|
6845
|
+
updatedAt: responseData.updatedAt,
|
|
6846
|
+
userId: responseData.userId,
|
|
6847
|
+
products: responseData.products
|
|
6848
|
+
});
|
|
6849
|
+
} catch (error) {
|
|
6850
|
+
console.error("Error fetching wishlist:", error);
|
|
6851
|
+
setState((prev) => ({
|
|
6852
|
+
...prev,
|
|
6853
|
+
isLoading: false,
|
|
6854
|
+
error: error instanceof Error ? error.message : "Failed to load wishlist"
|
|
6855
|
+
}));
|
|
6856
|
+
}
|
|
6857
|
+
}, [isAuthenticated]);
|
|
6858
|
+
useEffect(() => {
|
|
6859
|
+
fetchWishlist();
|
|
6860
|
+
}, [fetchWishlist]);
|
|
6861
|
+
const addToWishlist = async (product) => {
|
|
6862
|
+
if (!isAuthenticated) {
|
|
6863
|
+
toast.error("Please sign in to add items to your wishlist");
|
|
6864
|
+
return;
|
|
6865
|
+
}
|
|
6866
|
+
try {
|
|
6867
|
+
if (isInWishlist(product?._id || "")) {
|
|
6868
|
+
toast.info("This item is already in your wishlist");
|
|
6869
|
+
return;
|
|
6870
|
+
}
|
|
6871
|
+
await wishlistApi.addToWishlist(product?._id || "");
|
|
6872
|
+
await fetchWishlist();
|
|
6873
|
+
toast.success("Added to wishlist");
|
|
6874
|
+
} catch (error) {
|
|
6875
|
+
console.error("Error adding to wishlist:", error);
|
|
6876
|
+
toast.error("Failed to add to wishlist");
|
|
6877
|
+
throw error;
|
|
6878
|
+
}
|
|
6879
|
+
};
|
|
6880
|
+
const removeFromWishlist = async (productId) => {
|
|
6881
|
+
try {
|
|
6882
|
+
await wishlistApi.removeFromWishlist(productId);
|
|
6883
|
+
setState((prev) => {
|
|
6884
|
+
const newProducts = prev.products.filter((product) => product?._id !== productId);
|
|
6885
|
+
return {
|
|
6886
|
+
...prev,
|
|
6887
|
+
products: newProducts
|
|
6888
|
+
};
|
|
6889
|
+
});
|
|
6890
|
+
toast.success("Removed from wishlist");
|
|
6891
|
+
} catch (error) {
|
|
6892
|
+
console.error("Error removing from wishlist:", error);
|
|
6893
|
+
toast.error("Failed to remove from wishlist");
|
|
6894
|
+
throw error;
|
|
6895
|
+
}
|
|
6896
|
+
};
|
|
6897
|
+
const clearWishlist = async () => {
|
|
6898
|
+
try {
|
|
6899
|
+
await wishlistApi.clearWishlist();
|
|
6900
|
+
setState((prev) => ({
|
|
6901
|
+
...prev,
|
|
6902
|
+
products: []
|
|
6903
|
+
}));
|
|
6904
|
+
toast.success("Wishlist cleared");
|
|
6905
|
+
} catch (error) {
|
|
6906
|
+
console.error("Error clearing wishlist:", error);
|
|
6907
|
+
toast.error("Failed to clear wishlist");
|
|
6908
|
+
throw error;
|
|
6909
|
+
}
|
|
6910
|
+
};
|
|
6911
|
+
const isInWishlist = (productId) => {
|
|
6912
|
+
return state.products.some((product) => product?._id === productId);
|
|
6913
|
+
};
|
|
6914
|
+
const getWishlistCount = () => {
|
|
6915
|
+
return state.products.length;
|
|
6916
|
+
};
|
|
6917
|
+
const refreshWishlist = async () => {
|
|
6918
|
+
await fetchWishlist();
|
|
6919
|
+
};
|
|
6920
|
+
return /* @__PURE__ */ React19.createElement(
|
|
6921
|
+
WishlistContext.Provider,
|
|
6922
|
+
{
|
|
6923
|
+
value: {
|
|
6924
|
+
...state,
|
|
6925
|
+
addToWishlist,
|
|
6926
|
+
removeFromWishlist,
|
|
6927
|
+
isInWishlist,
|
|
6928
|
+
getWishlistCount,
|
|
6929
|
+
refreshWishlist,
|
|
6930
|
+
clearWishlist
|
|
6931
|
+
}
|
|
6932
|
+
},
|
|
6933
|
+
children
|
|
6934
|
+
);
|
|
6935
|
+
}
|
|
6936
|
+
var useWishlist = () => {
|
|
6937
|
+
const context = useContext(WishlistContext);
|
|
6938
|
+
if (context === void 0) {
|
|
6939
|
+
throw new Error("useWishlist must be used within a WishlistProvider");
|
|
6940
|
+
}
|
|
6941
|
+
return context;
|
|
6942
|
+
};
|
|
6475
6943
|
function EcommerceProvider({ config, children }) {
|
|
6476
6944
|
useEffect(() => {
|
|
6477
6945
|
initializeApiAdapter(config);
|
|
@@ -6479,7 +6947,7 @@ function EcommerceProvider({ config, children }) {
|
|
|
6479
6947
|
const [client] = React19.useState(
|
|
6480
6948
|
new QueryClient({ defaultOptions: { queries: { staleTime: 5e3 } } })
|
|
6481
6949
|
);
|
|
6482
|
-
return /* @__PURE__ */ React19.createElement(QueryClientProvider, { client }, /* @__PURE__ */ React19.createElement(ThemeProvider, { config }, /* @__PURE__ */ React19.createElement(AuthProvider, null, /* @__PURE__ */ React19.createElement(CartProvider, null, children, /* @__PURE__ */ React19.createElement(Toaster, { position: "top-right", richColors: true })))));
|
|
6950
|
+
return /* @__PURE__ */ React19.createElement(QueryClientProvider, { client }, /* @__PURE__ */ React19.createElement(ThemeProvider, { config }, /* @__PURE__ */ React19.createElement(AuthProvider, null, /* @__PURE__ */ React19.createElement(CartProvider, null, /* @__PURE__ */ React19.createElement(WishlistProvider, null, children, /* @__PURE__ */ React19.createElement(Toaster, { position: "top-right", richColors: true }))))));
|
|
6483
6951
|
}
|
|
6484
6952
|
|
|
6485
6953
|
// src/lib/utils/format.ts
|
|
@@ -6513,45 +6981,6 @@ function truncate(text, maxLength) {
|
|
|
6513
6981
|
function getInitials(firstName, lastName) {
|
|
6514
6982
|
return `${firstName?.charAt(0)}${lastName?.charAt(0)}`.toUpperCase();
|
|
6515
6983
|
}
|
|
6516
|
-
var BaseUrl = "https://api.heypharmacist.com";
|
|
6517
|
-
globalAxios4.interceptors.request.use(async (config) => {
|
|
6518
|
-
if (!config?.headers) {
|
|
6519
|
-
throw new Error(
|
|
6520
|
-
`Expected 'config' and 'config.headers' not to be undefined`
|
|
6521
|
-
);
|
|
6522
|
-
}
|
|
6523
|
-
if (typeof window !== "undefined") {
|
|
6524
|
-
try {
|
|
6525
|
-
const ecommerceConfig = getCurrentConfig();
|
|
6526
|
-
const token = getAuthToken();
|
|
6527
|
-
if (token) {
|
|
6528
|
-
config.headers.Authorization = `Bearer ${token}`;
|
|
6529
|
-
}
|
|
6530
|
-
if (ecommerceConfig?.storeId) {
|
|
6531
|
-
config.headers["X-Store-Key"] = ecommerceConfig.storeId;
|
|
6532
|
-
}
|
|
6533
|
-
} catch (error) {
|
|
6534
|
-
console.warn("API configuration not initialized yet:", error);
|
|
6535
|
-
}
|
|
6536
|
-
}
|
|
6537
|
-
return config;
|
|
6538
|
-
});
|
|
6539
|
-
var ABORT_CONTROLLER = new AbortController();
|
|
6540
|
-
var AXIOS_CONFIG = new Configuration({
|
|
6541
|
-
basePath: BaseUrl,
|
|
6542
|
-
baseOptions: {
|
|
6543
|
-
signal: ABORT_CONTROLLER.signal,
|
|
6544
|
-
timeout: 2e4
|
|
6545
|
-
}
|
|
6546
|
-
});
|
|
6547
|
-
var WishlistContext = createContext(void 0);
|
|
6548
|
-
var useWishlist = () => {
|
|
6549
|
-
const context = useContext(WishlistContext);
|
|
6550
|
-
if (context === void 0) {
|
|
6551
|
-
throw new Error("useWishlist must be used within a WishlistProvider");
|
|
6552
|
-
}
|
|
6553
|
-
return context;
|
|
6554
|
-
};
|
|
6555
6984
|
function ProductCard({
|
|
6556
6985
|
product,
|
|
6557
6986
|
onClickProduct,
|