flowrix 1.0.1-beta.8 → 1.0.1-beta.80

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.
Files changed (192) hide show
  1. package/dist/module.d.mts +1 -6
  2. package/dist/module.json +1 -1
  3. package/dist/module.mjs +94 -29
  4. package/dist/runtime/composables/Blog/useBlogIndex.d.ts +2 -5
  5. package/dist/runtime/composables/Brand/brand.js +2 -0
  6. package/dist/runtime/composables/Cart/useCart.d.ts +40 -0
  7. package/dist/runtime/composables/Cart/useCart.js +10 -0
  8. package/dist/runtime/composables/Cart/useCartDetail.d.ts +15 -5
  9. package/dist/runtime/composables/Cart/useCartDetail.js +3 -0
  10. package/dist/runtime/composables/Checkout/PaymentMethods/useFlowrixpay.d.ts +40 -1
  11. package/dist/runtime/composables/Checkout/PaymentMethods/useFlowrixpay.js +2 -2
  12. package/dist/runtime/composables/Checkout/PaymentMethods/useOpayo.d.ts +40 -1
  13. package/dist/runtime/composables/Checkout/PaymentMethods/useOpayo.js +2 -2
  14. package/dist/runtime/composables/Checkout/PaymentMethods/usePaymentMethods.js +3 -14
  15. package/dist/runtime/composables/Checkout/PaymentMethods/useStripe.d.ts +2 -2
  16. package/dist/runtime/composables/Checkout/useCheckout.d.ts +84 -73
  17. package/dist/runtime/composables/Checkout/useCheckout.js +36 -28
  18. package/dist/runtime/composables/Checkout/{useBillingAddress.d.ts → useCheckoutBillingAddress.d.ts} +6 -6
  19. package/dist/runtime/composables/Checkout/{useBillingAddress.js → useCheckoutBillingAddress.js} +6 -1
  20. package/dist/runtime/composables/Checkout/{useShippingAddress.d.ts → useCheckoutShippingAddress.d.ts} +1 -1
  21. package/dist/runtime/composables/Checkout/{useShippingAddress.js → useCheckoutShippingAddress.js} +7 -2
  22. package/dist/runtime/composables/Checkout/useCreateAccount.d.ts +7 -7
  23. package/dist/runtime/composables/Checkout/useCreateAccount.js +3 -1
  24. package/dist/runtime/composables/Checkout/useDeliveryMethod.d.ts +2 -2
  25. package/dist/runtime/composables/Checkout/useDeliveryMethod.js +8 -7
  26. package/dist/runtime/composables/Customer/useBillingAddress.d.ts +112 -0
  27. package/dist/runtime/composables/Customer/useBillingAddress.js +93 -0
  28. package/dist/runtime/composables/Customer/useLogin.d.ts +9 -0
  29. package/dist/runtime/composables/Customer/useLogin.js +34 -0
  30. package/dist/runtime/composables/Customer/useOrders.d.ts +29 -0
  31. package/dist/runtime/composables/Customer/useOrders.js +56 -0
  32. package/dist/runtime/composables/Customer/usePasswordReset.d.ts +26 -0
  33. package/dist/runtime/composables/Customer/usePasswordReset.js +258 -0
  34. package/dist/runtime/composables/Customer/useProfile.d.ts +75 -0
  35. package/dist/runtime/composables/Customer/useProfile.js +106 -0
  36. package/dist/runtime/composables/Customer/useQuotations.d.ts +32 -0
  37. package/dist/runtime/composables/Customer/useQuotations.js +40 -0
  38. package/dist/runtime/composables/Customer/useRegister.d.ts +118 -11
  39. package/dist/runtime/composables/Customer/useRegister.js +236 -34
  40. package/dist/runtime/composables/Customer/useShippingAddress.d.ts +121 -0
  41. package/dist/runtime/composables/Customer/useShippingAddress.js +145 -0
  42. package/dist/runtime/composables/Customer/useUpdatePassword.d.ts +21 -0
  43. package/dist/runtime/composables/Customer/useUpdatePassword.js +94 -0
  44. package/dist/runtime/composables/Customer/useUserCards.d.ts +22 -0
  45. package/dist/runtime/composables/Customer/useUserCards.js +65 -0
  46. package/dist/runtime/composables/{useWishlists.d.ts → Customer/useWishlists.d.ts} +5 -18
  47. package/dist/runtime/composables/{useWishlists.js → Customer/useWishlists.js} +19 -28
  48. package/dist/runtime/composables/Extras/useCountry.d.ts +11 -6
  49. package/dist/runtime/composables/Extras/useCountry.js +5 -4
  50. package/dist/runtime/composables/Header/useHeader.d.ts +6 -20
  51. package/dist/runtime/composables/Header/useHeader.js +3 -2
  52. package/dist/runtime/composables/Product/CustomProduct/useSteps.d.ts +1 -1
  53. package/dist/runtime/composables/Product/useProductSlug.d.ts +8 -1
  54. package/dist/runtime/composables/Product/useQuickView.d.ts +8 -0
  55. package/dist/runtime/composables/Product/useQuickView.js +27 -0
  56. package/dist/runtime/composables/Product/useService.d.ts +1 -1
  57. package/dist/runtime/composables/Product/useService.js +0 -3
  58. package/dist/runtime/composables/SideBar/Filters/useFilters.d.ts +2 -2
  59. package/dist/runtime/composables/SideBar/Filters/useSorting.d.ts +2 -2
  60. package/dist/runtime/composables/index.d.ts +15 -12
  61. package/dist/runtime/composables/index.js +15 -12
  62. package/dist/runtime/composables/useAddresses.js +6 -6
  63. package/dist/runtime/composables/useCards.js +2 -2
  64. package/dist/runtime/composables/useLocation.d.ts +2 -12
  65. package/dist/runtime/composables/useQuotationCheckout.d.ts +78 -0
  66. package/dist/runtime/composables/useQuotationCheckout.js +138 -0
  67. package/dist/runtime/middleware/flowrix.d.ts +5 -4
  68. package/dist/runtime/middleware/flowrix.js +41 -21
  69. package/dist/runtime/plugin.d.ts +1 -1
  70. package/dist/runtime/server/api/albums.js +1 -1
  71. package/dist/runtime/server/api/auth/forgot.js +1 -1
  72. package/dist/runtime/server/api/auth/login.js +5 -6
  73. package/dist/runtime/server/api/auth/logout.js +1 -1
  74. package/dist/runtime/server/api/auth/register.js +1 -1
  75. package/dist/runtime/server/api/auth/session.get.js +1 -1
  76. package/dist/runtime/server/api/auth/user/reset-password.js +1 -1
  77. package/dist/runtime/server/api/auth/user/session.js +1 -1
  78. package/dist/runtime/server/api/auth/user/verify-token.js +1 -1
  79. package/dist/runtime/server/api/banners.js +2 -2
  80. package/dist/runtime/server/api/brand/{[slug].js → [...slug].js} +17 -17
  81. package/dist/runtime/server/api/brand/index.d.ts +2 -0
  82. package/dist/runtime/server/api/brand/index.js +23 -0
  83. package/dist/runtime/server/api/cache/[...slug].delete.d.ts +2 -0
  84. package/dist/runtime/server/api/cache/[...slug].delete.js +40 -0
  85. package/dist/runtime/server/api/cache/clean.get.d.ts +5 -0
  86. package/dist/runtime/server/api/cache/clean.get.js +16 -0
  87. package/dist/runtime/server/api/cart/[slug]/add.js +1 -1
  88. package/dist/runtime/server/api/cart/[slug]/update.js +1 -1
  89. package/dist/runtime/server/api/cart/related.d.ts +2 -0
  90. package/dist/runtime/server/api/cart/related.js +21 -0
  91. package/dist/runtime/server/api/cart/remove.js +1 -1
  92. package/dist/runtime/server/api/cart/service/[slug]/add.js +1 -1
  93. package/dist/runtime/server/api/catalog/categories.js +5 -4
  94. package/dist/runtime/server/api/catalog/categoriesall.d.ts +3 -0
  95. package/dist/runtime/server/api/catalog/categoriesall.js +44 -0
  96. package/dist/runtime/server/api/catalog/featured.js +5 -4
  97. package/dist/runtime/server/api/catalog/samples.js +5 -4
  98. package/dist/runtime/server/api/catalog/search.js +5 -4
  99. package/dist/runtime/server/api/category/[...slug].js +18 -14
  100. package/dist/runtime/server/api/checkout/applyCoupon.js +1 -1
  101. package/dist/runtime/server/api/checkout/configs.d.ts +1 -1
  102. package/dist/runtime/server/api/checkout/configs.js +10 -11
  103. package/dist/runtime/server/api/checkout/countries.js +1 -1
  104. package/dist/runtime/server/api/checkout/paymentmethod.js +7 -7
  105. package/dist/runtime/server/api/checkout/quotation/[slug].d.ts +2 -0
  106. package/dist/runtime/server/api/checkout/quotation/[slug].js +21 -0
  107. package/dist/runtime/server/api/checkout/quotation/guest/[slug].d.ts +2 -0
  108. package/dist/runtime/server/api/checkout/quotation/guest/[slug].js +37 -0
  109. package/dist/runtime/server/api/checkout/quotation/guest/customer.d.ts +2 -0
  110. package/dist/runtime/server/api/checkout/quotation/guest/customer.js +21 -0
  111. package/dist/runtime/server/api/checkout/quotation/submit/[slug].d.ts +2 -0
  112. package/dist/runtime/server/api/checkout/quotation/submit/[slug].js +23 -0
  113. package/dist/runtime/server/api/{blog/[slug].js → cmspost/[...slug].js} +7 -9
  114. package/dist/runtime/server/api/{blog/blog.js → cmspost/all.js} +2 -2
  115. package/dist/runtime/server/api/company/profile.d.ts +1 -1
  116. package/dist/runtime/server/api/company/profile.js +9 -9
  117. package/dist/runtime/server/api/contact-center/webforms/[id]/details.js +1 -1
  118. package/dist/runtime/server/api/contact-center/webforms/create.js +1 -1
  119. package/dist/runtime/server/api/countries.d.ts +2 -0
  120. package/dist/runtime/server/api/countries.js +35 -0
  121. package/dist/runtime/server/api/customer/address/add.js +1 -1
  122. package/dist/runtime/server/api/customer/address/delete.js +2 -2
  123. package/dist/runtime/server/api/customer/address/setshipping.js +1 -1
  124. package/dist/runtime/server/api/customer/address/update.js +1 -1
  125. package/dist/runtime/server/api/customer/cards/delete.js +2 -2
  126. package/dist/runtime/server/api/customer/cards/get.js +2 -2
  127. package/dist/runtime/server/api/customer/change-password.js +2 -2
  128. package/dist/runtime/server/api/customer/checkout.js +1 -1
  129. package/dist/runtime/server/api/customer/orders.js +2 -2
  130. package/dist/runtime/server/api/customer/profile/update.js +1 -1
  131. package/dist/runtime/server/api/customer/quotations.js +2 -2
  132. package/dist/runtime/server/api/customer/search.js +1 -1
  133. package/dist/runtime/server/api/customer/tax-invoice.js +1 -1
  134. package/dist/runtime/server/api/customer/wishlist/add.js +1 -1
  135. package/dist/runtime/server/api/customer/wishlist/createWishList.js +1 -1
  136. package/dist/runtime/server/api/customer/wishlist/deleteFromWishList.js +1 -1
  137. package/dist/runtime/server/api/customer/wishlist/deleteWishList.js +1 -1
  138. package/dist/runtime/server/api/customer/wishlist/get.js +2 -2
  139. package/dist/runtime/server/api/customer/wishlist/getWishListItems.js +1 -1
  140. package/dist/runtime/server/api/customer/wishlist/updateWishList.js +2 -2
  141. package/dist/runtime/server/api/featured.d.ts +2 -0
  142. package/dist/runtime/server/api/featured.js +16 -0
  143. package/dist/runtime/server/api/location.js +1 -1
  144. package/dist/runtime/server/api/nav/[id]/links.js +1 -1
  145. package/dist/runtime/server/api/page/{[slug].js → [...slug].js} +6 -8
  146. package/dist/runtime/server/api/product/[...slug].js +8 -5
  147. package/dist/runtime/server/api/quickview/[slug].d.ts +2 -0
  148. package/dist/runtime/server/api/quickview/[slug].js +16 -0
  149. package/dist/runtime/server/api/samples.d.ts +3 -0
  150. package/dist/runtime/server/api/samples.js +20 -0
  151. package/dist/runtime/server/api/search.d.ts +3 -0
  152. package/dist/runtime/server/api/search.js +15 -0
  153. package/dist/runtime/server/api/service/[slug].js +5 -4
  154. package/dist/runtime/server/api/service/availability.js +1 -1
  155. package/dist/runtime/server/api/service/getall.d.ts +3 -0
  156. package/dist/runtime/server/api/service/getall.js +52 -0
  157. package/dist/runtime/server/api/shop.d.ts +3 -0
  158. package/dist/runtime/server/api/shop.js +15 -0
  159. package/dist/runtime/server/api/subscribe.js +1 -1
  160. package/dist/runtime/server/api/v2/[...slug].js +3 -1
  161. package/dist/runtime/server/api/webform.d.ts +3 -0
  162. package/dist/runtime/server/api/webform.js +16 -0
  163. package/dist/runtime/stores/Cart.d.ts +12 -0
  164. package/dist/runtime/stores/Cart.js +50 -16
  165. package/dist/runtime/stores/Checkout.d.ts +9 -15
  166. package/dist/runtime/stores/Checkout.js +19 -5
  167. package/dist/runtime/stores/Search.d.ts +1 -1
  168. package/dist/runtime/stores/Services.js +2 -2
  169. package/dist/runtime/stores/auth.d.ts +8 -11
  170. package/dist/runtime/stores/auth.js +390 -8
  171. package/dist/runtime/stores/countries.d.ts +1 -3
  172. package/dist/runtime/stores/countries.js +4 -8
  173. package/dist/runtime/stores/product/slug.d.ts +1 -17
  174. package/dist/runtime/stores/wishlists.d.ts +105 -5
  175. package/dist/runtime/stores/wishlists.js +200 -9
  176. package/dist/runtime/utils/api.js +9 -13
  177. package/dist/runtime/utils/htmlCache.d.ts +5 -0
  178. package/dist/runtime/utils/htmlCache.js +60 -0
  179. package/dist/types.d.mts +6 -2
  180. package/package.json +32 -20
  181. package/dist/runtime/composables/useAuth.d.ts +0 -45
  182. package/dist/runtime/composables/useAuth.js +0 -180
  183. package/dist/runtime/composables/useCountries.d.ts +0 -12
  184. package/dist/runtime/composables/useCountries.js +0 -50
  185. package/dist/runtime/composables/useOrders.d.ts +0 -21
  186. package/dist/runtime/composables/useOrders.js +0 -82
  187. package/dist/runtime/composables/useQuotations.d.ts +0 -14
  188. package/dist/runtime/composables/useQuotations.js +0 -50
  189. /package/dist/runtime/server/api/brand/{[slug].d.ts → [...slug].d.ts} +0 -0
  190. /package/dist/runtime/server/api/{blog/[slug].d.ts → cmspost/[...slug].d.ts} +0 -0
  191. /package/dist/runtime/server/api/{blog/blog.d.ts → cmspost/all.d.ts} +0 -0
  192. /package/dist/runtime/server/api/page/{[slug].d.ts → [...slug].d.ts} +0 -0
@@ -0,0 +1,93 @@
1
+ import { ref, computed } from "vue";
2
+ import { useAuthStore } from "../../stores/auth.js";
3
+ export function useBillingAddress() {
4
+ const authStore = useAuthStore();
5
+ const user = computed(() => authStore.user);
6
+ const userBillingAddress = computed(
7
+ () => user.value?.addresses?.find((address) => address.billing == 1)
8
+ );
9
+ const billingForm = ref({
10
+ id: userBillingAddress.value?.id || "",
11
+ firstname: userBillingAddress.value?.firstname || "",
12
+ lastname: userBillingAddress.value?.lastname || "",
13
+ saddress: userBillingAddress.value?.address || "",
14
+ suburb: userBillingAddress.value?.suburb || "",
15
+ state: userBillingAddress.value?.state || "",
16
+ state_id: userBillingAddress.value?.state_id || "",
17
+ country: userBillingAddress.value?.country || "",
18
+ country_id: userBillingAddress.value?.country_id || "",
19
+ postcode: userBillingAddress.value?.postcode || "",
20
+ mobile: userBillingAddress.value?.mobile || "",
21
+ shipping: userBillingAddress.value?.shipping || "",
22
+ billing: userBillingAddress.value?.billing || 1
23
+ });
24
+ const successMessage = ref("");
25
+ const errorMessage = ref("");
26
+ const isEditing = ref(false);
27
+ const loading = ref(false);
28
+ const submitAddressReturn = ref(null);
29
+ const clearMessages = () => {
30
+ successMessage.value = "";
31
+ errorMessage.value = "";
32
+ submitAddressReturn.value = null;
33
+ };
34
+ const resetForm = () => {
35
+ billingForm.value = {
36
+ id: userBillingAddress.value?.id || "",
37
+ firstname: userBillingAddress.value?.firstname || "",
38
+ lastname: userBillingAddress.value?.lastname || "",
39
+ saddress: userBillingAddress.value?.address || "",
40
+ suburb: userBillingAddress.value?.suburb || "",
41
+ state: userBillingAddress.value?.state || "",
42
+ state_id: userBillingAddress.value?.state_id || "",
43
+ country: userBillingAddress.value?.country || "",
44
+ country_id: userBillingAddress.value?.country_id || "",
45
+ postcode: userBillingAddress.value?.postcode || "",
46
+ mobile: userBillingAddress.value?.mobile || "",
47
+ shipping: userBillingAddress.value?.shipping || "",
48
+ billing: userBillingAddress.value?.billing || 1
49
+ };
50
+ };
51
+ const cancelEdit = () => {
52
+ resetForm();
53
+ isEditing.value = false;
54
+ clearMessages();
55
+ };
56
+ const submitAddress = async () => {
57
+ loading.value = true;
58
+ clearMessages();
59
+ try {
60
+ const method = billingForm.value.id ? "update" : "add";
61
+ submitAddressReturn.value = await authStore.setAddress(billingForm.value, method);
62
+ if (submitAddressReturn.value?.status === "Success") {
63
+ await authStore.fetchProfile();
64
+ isEditing.value = false;
65
+ successMessage.value = billingForm.value.id ? "Billing Address updated successfully" : "Billing Address created successfully";
66
+ } else {
67
+ errorMessage.value = submitAddressReturn.value?.message || "Failed to save address";
68
+ }
69
+ } catch (error) {
70
+ console.error("Address submission error:", error);
71
+ errorMessage.value = error.message || "Failed to save address. Please try again.";
72
+ } finally {
73
+ loading.value = false;
74
+ }
75
+ };
76
+ return {
77
+ // State
78
+ billingForm,
79
+ successMessage,
80
+ errorMessage,
81
+ isEditing,
82
+ loading,
83
+ submitAddressReturn,
84
+ // Computed
85
+ user,
86
+ userBillingAddress,
87
+ // Methods
88
+ clearMessages,
89
+ cancelEdit,
90
+ submitAddress,
91
+ resetForm
92
+ };
93
+ }
@@ -0,0 +1,9 @@
1
+ export default function (): {
2
+ router: any;
3
+ route: any;
4
+ email: import("vue").Ref<string, string>;
5
+ password: import("vue").Ref<string, string>;
6
+ CustomerLogin: () => Promise<void>;
7
+ logResponse: import("vue").Ref<any, any>;
8
+ isLoading: import("vue").Ref<boolean, boolean>;
9
+ };
@@ -0,0 +1,34 @@
1
+ import { ref } from "vue";
2
+ import { useRouter, useRoute } from "#vue-router";
3
+ import { useAuthStore } from "../../stores/auth.js";
4
+ export default function() {
5
+ const router = useRouter();
6
+ const route = useRoute();
7
+ const email = ref("");
8
+ const password = ref("");
9
+ const logResponse = ref(null);
10
+ const isLoading = ref(false);
11
+ const CustomerLogin = async () => {
12
+ isLoading.value = true;
13
+ try {
14
+ const loginFields = {
15
+ email: email.value,
16
+ password: password.value
17
+ };
18
+ logResponse.value = await useAuthStore().userLogin(loginFields);
19
+ } catch (error) {
20
+ logResponse.value = { status: "Error", message: "Login failed" };
21
+ } finally {
22
+ isLoading.value = false;
23
+ }
24
+ };
25
+ return {
26
+ router,
27
+ route,
28
+ email,
29
+ password,
30
+ CustomerLogin,
31
+ logResponse,
32
+ isLoading
33
+ };
34
+ }
@@ -0,0 +1,29 @@
1
+ export interface Order {
2
+ order_no: string;
3
+ order_status: string;
4
+ payment_method: string;
5
+ grandtotal: number;
6
+ [key: string]: any;
7
+ }
8
+ export declare function useOrders(): {
9
+ orders: import("vue").Ref<{
10
+ [x: string]: any;
11
+ order_no: string;
12
+ order_status: string;
13
+ payment_method: string;
14
+ grandtotal: number;
15
+ }[], Order[] | {
16
+ [x: string]: any;
17
+ order_no: string;
18
+ order_status: string;
19
+ payment_method: string;
20
+ grandtotal: number;
21
+ }[]>;
22
+ pending: import("vue").Ref<boolean, boolean>;
23
+ loadingInvoice: import("vue").Ref<string, string>;
24
+ downloadError: import("vue").Ref<string, string>;
25
+ loadOrders: () => Promise<void>;
26
+ generateInvoice: (invoiceNumber: string) => Promise<void>;
27
+ clearError: () => void;
28
+ hasOrders: () => boolean;
29
+ };
@@ -0,0 +1,56 @@
1
+ import { ref } from "vue";
2
+ import { useAuthStore } from "../../stores/auth.js";
3
+ export function useOrders() {
4
+ const authStore = useAuthStore();
5
+ const orders = ref([]);
6
+ const pending = ref(true);
7
+ const loadingInvoice = ref("");
8
+ const downloadError = ref("");
9
+ const loadOrders = async () => {
10
+ pending.value = true;
11
+ downloadError.value = "";
12
+ try {
13
+ const ordersData = await authStore.fetchOrders();
14
+ orders.value = Array.isArray(ordersData) ? ordersData : [];
15
+ } catch (error) {
16
+ console.error("Failed to load orders:", error);
17
+ orders.value = [];
18
+ downloadError.value = "Failed to load orders. Please try again.";
19
+ } finally {
20
+ pending.value = false;
21
+ }
22
+ };
23
+ const generateInvoice = async (invoiceNumber) => {
24
+ loadingInvoice.value = invoiceNumber;
25
+ downloadError.value = "";
26
+ try {
27
+ const response = await authStore.downloadInvoice(invoiceNumber);
28
+ if (response && response.type === void 0) {
29
+ downloadError.value = "Invoice cannot be downloaded. Please try again...";
30
+ }
31
+ } catch (error) {
32
+ console.error("Invoice download error:", error);
33
+ downloadError.value = error.message || "Invoice cannot be downloaded. Please try again...";
34
+ } finally {
35
+ loadingInvoice.value = "";
36
+ }
37
+ };
38
+ const clearError = () => {
39
+ downloadError.value = "";
40
+ };
41
+ const hasOrders = () => {
42
+ return orders.value && orders.value.length > 0;
43
+ };
44
+ return {
45
+ // State
46
+ orders,
47
+ pending,
48
+ loadingInvoice,
49
+ downloadError,
50
+ // Methods
51
+ loadOrders,
52
+ generateInvoice,
53
+ clearError,
54
+ hasOrders
55
+ };
56
+ }
@@ -0,0 +1,26 @@
1
+ export default function (timerDuration?: number): {
2
+ email: import("vue").Ref<string, string>;
3
+ resetCode: import("vue").Ref<string, string>;
4
+ newPassword: import("vue").Ref<string, string>;
5
+ confirmPassword: import("vue").Ref<string, string>;
6
+ showPassword: import("vue").Ref<boolean, boolean>;
7
+ showConfirmPassword: import("vue").Ref<boolean, boolean>;
8
+ isLoading: import("vue").Ref<boolean, boolean>;
9
+ errorMessage: import("vue").Ref<string, string>;
10
+ successMessage: import("vue").Ref<string, string>;
11
+ isCodeSent: import("vue").Ref<boolean, boolean>;
12
+ isCodeVerified: import("vue").Ref<boolean, boolean>;
13
+ currentStep: import("vue").Ref<number, number>;
14
+ timerCount: import("vue").Ref<number, number>;
15
+ isTimerActive: import("vue").Ref<boolean, boolean>;
16
+ formatTime: (seconds: number) => string;
17
+ togglePassword: (field: "newPassword" | "confirmPassword") => void;
18
+ handleSubmit: () => Promise<void>;
19
+ resetForm: () => void;
20
+ resendCode: () => Promise<void>;
21
+ startTimer: (duration?: number) => void;
22
+ stopTimer: () => void;
23
+ resetTimer: (duration?: number) => void;
24
+ cleanup: () => void;
25
+ router: any;
26
+ };
@@ -0,0 +1,258 @@
1
+ import { ref } from "vue";
2
+ import { useRouter, useRoute } from "#vue-router";
3
+ import { useAuthStore } from "../../stores/auth.js";
4
+ export default function(timerDuration = 60) {
5
+ const router = useRouter();
6
+ const route = useRoute();
7
+ const authStore = useAuthStore();
8
+ const email = ref("");
9
+ const resetCode = ref("");
10
+ const newPassword = ref("");
11
+ const confirmPassword = ref("");
12
+ const showPassword = ref(false);
13
+ const showConfirmPassword = ref(false);
14
+ const isLoading = ref(false);
15
+ const errorMessage = ref("");
16
+ const successMessage = ref("");
17
+ const isCodeSent = ref(false);
18
+ const isCodeVerified = ref(false);
19
+ const currentStep = ref(1);
20
+ const verifiedToken = ref("");
21
+ const timerCount = ref(timerDuration);
22
+ const isTimerActive = ref(false);
23
+ const timerInterval = ref(null);
24
+ const validateEmail = (email2) => {
25
+ return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email2);
26
+ };
27
+ const togglePassword = (field) => {
28
+ if (field === "newPassword") {
29
+ showPassword.value = !showPassword.value;
30
+ } else {
31
+ showConfirmPassword.value = !showConfirmPassword.value;
32
+ }
33
+ };
34
+ const startTimer = (duration = timerDuration) => {
35
+ isTimerActive.value = true;
36
+ timerCount.value = duration;
37
+ timerInterval.value = setInterval(() => {
38
+ timerCount.value--;
39
+ if (timerCount.value <= 0) {
40
+ clearInterval(timerInterval.value);
41
+ isTimerActive.value = false;
42
+ }
43
+ }, 1e3);
44
+ };
45
+ const stopTimer = () => {
46
+ if (timerInterval.value) {
47
+ clearInterval(timerInterval.value);
48
+ timerInterval.value = null;
49
+ }
50
+ isTimerActive.value = false;
51
+ };
52
+ const resetTimer = (duration = timerDuration) => {
53
+ stopTimer();
54
+ timerCount.value = duration;
55
+ };
56
+ const formatTime = (seconds) => {
57
+ const mins = Math.floor(seconds / 60);
58
+ const secs = seconds % 60;
59
+ return `${mins}:${secs < 10 ? "0" : ""}${secs}`;
60
+ };
61
+ const resendCode = async () => {
62
+ if (!validateEmail(email.value)) {
63
+ errorMessage.value = "Please enter a valid email address";
64
+ return;
65
+ }
66
+ isLoading.value = true;
67
+ errorMessage.value = "";
68
+ successMessage.value = "";
69
+ try {
70
+ const response = await authStore.verifyEmail(email.value.trim());
71
+ if (response.status === "Success") {
72
+ successMessage.value = "Reset code sent to your email again!";
73
+ errorMessage.value = "";
74
+ startTimer();
75
+ } else {
76
+ errorMessage.value = formatErrorMessage(response.message) || "Failed to resend reset code. Please try again.";
77
+ successMessage.value = "";
78
+ }
79
+ } catch (error) {
80
+ errorMessage.value = "An error occurred while resending code. Please try again.";
81
+ successMessage.value = "";
82
+ } finally {
83
+ isLoading.value = false;
84
+ }
85
+ };
86
+ const sendResetCode = async () => {
87
+ if (!validateEmail(email.value)) {
88
+ errorMessage.value = "Please enter a valid email address";
89
+ successMessage.value = "";
90
+ return;
91
+ }
92
+ isLoading.value = true;
93
+ errorMessage.value = "";
94
+ successMessage.value = "";
95
+ try {
96
+ const response = await authStore.verifyEmail(email.value.trim());
97
+ if (response.status === "Success") {
98
+ successMessage.value = "Reset code sent to your email!";
99
+ errorMessage.value = "";
100
+ isCodeSent.value = true;
101
+ currentStep.value = 2;
102
+ startTimer();
103
+ } else {
104
+ errorMessage.value = formatErrorMessage(response.message) || "Failed to send reset code. Please try again.";
105
+ successMessage.value = "";
106
+ }
107
+ } catch (error) {
108
+ errorMessage.value = "An error occurred while sending reset code. Please try again.";
109
+ successMessage.value = "";
110
+ } finally {
111
+ isLoading.value = false;
112
+ }
113
+ };
114
+ const verifyResetCode = async () => {
115
+ if (!resetCode.value) {
116
+ errorMessage.value = "Please enter the reset code";
117
+ successMessage.value = "";
118
+ return;
119
+ }
120
+ isLoading.value = true;
121
+ errorMessage.value = "";
122
+ successMessage.value = "";
123
+ try {
124
+ const response = await authStore.verifyToken(email.value.trim(), resetCode.value.trim());
125
+ if (response.status === "Success") {
126
+ verifiedToken.value = response.data?.token || response.data;
127
+ successMessage.value = "Code verified successfully!";
128
+ errorMessage.value = "";
129
+ isCodeVerified.value = true;
130
+ currentStep.value = 3;
131
+ stopTimer();
132
+ } else {
133
+ errorMessage.value = formatErrorMessage(response.message) || "Invalid reset code. Please try again.";
134
+ successMessage.value = "";
135
+ }
136
+ } catch (error) {
137
+ errorMessage.value = "An error occurred while verifying code. Please try again.";
138
+ successMessage.value = "";
139
+ } finally {
140
+ isLoading.value = false;
141
+ }
142
+ };
143
+ const resetPasswordFunc = async () => {
144
+ if (newPassword.value !== confirmPassword.value) {
145
+ errorMessage.value = "Passwords do not match";
146
+ successMessage.value = "";
147
+ return;
148
+ }
149
+ if (newPassword.value.length < 8) {
150
+ errorMessage.value = "Password must be at least 8 characters long";
151
+ successMessage.value = "";
152
+ return;
153
+ }
154
+ isLoading.value = true;
155
+ errorMessage.value = "";
156
+ successMessage.value = "";
157
+ try {
158
+ const response = await authStore.resetPassword(
159
+ verifiedToken.value,
160
+ newPassword.value.trim(),
161
+ confirmPassword.value.trim()
162
+ );
163
+ if (response.status === "Success") {
164
+ const loginResponse = await authStore.userLogin({
165
+ email: email.value.trim(),
166
+ password: newPassword.value.trim()
167
+ });
168
+ if (loginResponse.status === "Success") {
169
+ resetForm();
170
+ successMessage.value = formatErrorMessage(response.message) || "Password reset successfully!";
171
+ errorMessage.value = "";
172
+ router.push("dashboard/profile");
173
+ } else {
174
+ successMessage.value = formatErrorMessage(response.message) || "Password reset successfully!";
175
+ errorMessage.value = "Password reset successful, but login failed. Please login manually.";
176
+ resetCode.value = "";
177
+ verifiedToken.value = "";
178
+ isCodeSent.value = false;
179
+ isCodeVerified.value = false;
180
+ currentStep.value = 1;
181
+ }
182
+ } else {
183
+ errorMessage.value = formatErrorMessage(response.message) || "Failed to reset password. Please try again.";
184
+ successMessage.value = "";
185
+ }
186
+ } catch (error) {
187
+ errorMessage.value = "An error occurred while resetting password. Please try again.";
188
+ successMessage.value = "";
189
+ } finally {
190
+ isLoading.value = false;
191
+ }
192
+ };
193
+ const handleSubmit = async () => {
194
+ if (currentStep.value === 1) {
195
+ await sendResetCode();
196
+ } else if (currentStep.value === 2) {
197
+ await verifyResetCode();
198
+ } else {
199
+ await resetPasswordFunc();
200
+ }
201
+ };
202
+ const formatErrorMessage = (message) => {
203
+ if (Array.isArray(message)) {
204
+ return message.join(", ");
205
+ }
206
+ return message;
207
+ };
208
+ const resetForm = () => {
209
+ email.value = "";
210
+ resetCode.value = "";
211
+ newPassword.value = "";
212
+ confirmPassword.value = "";
213
+ showPassword.value = false;
214
+ showConfirmPassword.value = false;
215
+ isLoading.value = false;
216
+ errorMessage.value = "";
217
+ successMessage.value = "";
218
+ isCodeSent.value = false;
219
+ isCodeVerified.value = false;
220
+ currentStep.value = 1;
221
+ verifiedToken.value = "";
222
+ stopTimer();
223
+ };
224
+ const cleanup = () => {
225
+ stopTimer();
226
+ };
227
+ return {
228
+ // State
229
+ email,
230
+ resetCode,
231
+ newPassword,
232
+ confirmPassword,
233
+ showPassword,
234
+ showConfirmPassword,
235
+ isLoading,
236
+ errorMessage,
237
+ successMessage,
238
+ isCodeSent,
239
+ isCodeVerified,
240
+ currentStep,
241
+ timerCount,
242
+ isTimerActive,
243
+ formatTime,
244
+ // Methods
245
+ togglePassword,
246
+ handleSubmit,
247
+ resetForm,
248
+ resendCode,
249
+ startTimer,
250
+ // Export startTimer for external control
251
+ stopTimer,
252
+ // Export stopTimer for external control
253
+ resetTimer,
254
+ // Export resetTimer for external control
255
+ cleanup,
256
+ router
257
+ };
258
+ }
@@ -0,0 +1,75 @@
1
+ export declare function useProfile(): {
2
+ profile: import("vue").Ref<{
3
+ firstName: string;
4
+ lastName: string;
5
+ email: string;
6
+ phone: string;
7
+ mobile: string;
8
+ dateOfBirth: string;
9
+ }, {
10
+ firstName: string;
11
+ lastName: string;
12
+ email: string;
13
+ phone: string;
14
+ mobile: string;
15
+ dateOfBirth: string;
16
+ } | {
17
+ firstName: string;
18
+ lastName: string;
19
+ email: string;
20
+ phone: string;
21
+ mobile: string;
22
+ dateOfBirth: string;
23
+ }>;
24
+ isEditing: import("vue").Ref<boolean, boolean>;
25
+ loading: import("vue").Ref<boolean, boolean>;
26
+ errorMessage: import("vue").Ref<string, string>;
27
+ successMessage: import("vue").Ref<string, string>;
28
+ dobFormatted: import("vue").WritableComputedRef<string, string>;
29
+ user: import("vue").ComputedRef<{
30
+ id: number;
31
+ fullname: string;
32
+ firstname: string;
33
+ lastname: string;
34
+ email: string;
35
+ avatar: string;
36
+ country_id: number | null;
37
+ country: {
38
+ id: number;
39
+ name: string;
40
+ emoji: string;
41
+ } | null;
42
+ state_id: number | null;
43
+ state: string | null;
44
+ suburb: string | null;
45
+ dob: string | null;
46
+ phone: string | null;
47
+ address: string | null;
48
+ mobile: string | null;
49
+ company: string | null;
50
+ addresses: {
51
+ id: number;
52
+ fullname: string | null;
53
+ firstname: string;
54
+ middlename: string | null;
55
+ lastname: string;
56
+ address: string;
57
+ suburb: string;
58
+ state: string | null;
59
+ state_id: number | null;
60
+ country: string;
61
+ country_id: number;
62
+ postcode: string;
63
+ mobile: string;
64
+ shipping: number;
65
+ billing: number;
66
+ }[];
67
+ created_at: string;
68
+ } | null>;
69
+ formatDisplayDate: (dateString: string) => string;
70
+ clearMessages: () => void;
71
+ cancelEdit: () => void;
72
+ updateCustomerProfile: () => Promise<void>;
73
+ initializeProfile: () => void;
74
+ resetProfile: () => void;
75
+ };
@@ -0,0 +1,106 @@
1
+ import { ref, computed } from "vue";
2
+ import { useAuthStore } from "../../stores/auth.js";
3
+ export function useProfile() {
4
+ const authStore = useAuthStore();
5
+ const user = computed(() => authStore.user);
6
+ const profile = ref({
7
+ firstName: user.value?.firstname || "",
8
+ lastName: user.value?.lastname || "",
9
+ email: user.value?.email || "",
10
+ phone: user.value?.phone || "",
11
+ mobile: user.value?.mobile || "",
12
+ dateOfBirth: user.value?.dob || ""
13
+ });
14
+ const isEditing = ref(false);
15
+ const loading = ref(false);
16
+ const errorMessage = ref("");
17
+ const successMessage = ref("");
18
+ const formatDisplayDate = (dateString) => {
19
+ if (!dateString) return "";
20
+ const date = new Date(dateString);
21
+ if (isNaN(date.getTime())) return dateString;
22
+ const months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
23
+ const day = date.getDate();
24
+ const month = months[date.getMonth()];
25
+ const year = date.getFullYear();
26
+ return `${month} ${day}, ${year}`;
27
+ };
28
+ const dobFormatted = computed({
29
+ get() {
30
+ return profile.value.dateOfBirth ? new Date(profile.value.dateOfBirth).toISOString().split("T")[0] : "";
31
+ },
32
+ set(value) {
33
+ profile.value.dateOfBirth = value;
34
+ }
35
+ });
36
+ const clearMessages = () => {
37
+ errorMessage.value = "";
38
+ successMessage.value = "";
39
+ };
40
+ const resetProfile = () => {
41
+ profile.value = {
42
+ firstName: user.value?.firstname || "",
43
+ lastName: user.value?.lastname || "",
44
+ email: user.value?.email || "",
45
+ phone: user.value?.phone || "",
46
+ mobile: user.value?.mobile || "",
47
+ dateOfBirth: user.value?.dob || ""
48
+ };
49
+ };
50
+ const cancelEdit = () => {
51
+ isEditing.value = false;
52
+ resetProfile();
53
+ clearMessages();
54
+ };
55
+ const updateCustomerProfile = async () => {
56
+ if (!profile.value.firstName?.trim() || !profile.value.lastName?.trim() || !profile.value.mobile?.trim()) {
57
+ errorMessage.value = "First name, Last name and Mobile are required!";
58
+ return;
59
+ }
60
+ loading.value = true;
61
+ errorMessage.value = "";
62
+ successMessage.value = "";
63
+ try {
64
+ const requestBody = {
65
+ firstname: profile.value.firstName.trim(),
66
+ lastname: profile.value.lastName.trim(),
67
+ phone: profile.value.phone?.trim() || "",
68
+ mobile: profile.value.mobile?.trim() || "",
69
+ dob: profile.value.dateOfBirth || ""
70
+ };
71
+ const response = await authStore.updateProfile(requestBody);
72
+ if (response.status === "Success") {
73
+ successMessage.value = response.message || "Profile updated successfully!";
74
+ isEditing.value = false;
75
+ } else {
76
+ errorMessage.value = response.message || "Failed to update profile. Please try again.";
77
+ }
78
+ } catch (err) {
79
+ console.error("Update error:", err);
80
+ errorMessage.value = err.message || "Failed to update profile. Please try again.";
81
+ } finally {
82
+ loading.value = false;
83
+ }
84
+ };
85
+ const initializeProfile = () => {
86
+ resetProfile();
87
+ };
88
+ return {
89
+ // State
90
+ profile,
91
+ isEditing,
92
+ loading,
93
+ errorMessage,
94
+ successMessage,
95
+ // Computed
96
+ dobFormatted,
97
+ user,
98
+ // Methods
99
+ formatDisplayDate,
100
+ clearMessages,
101
+ cancelEdit,
102
+ updateCustomerProfile,
103
+ initializeProfile,
104
+ resetProfile
105
+ };
106
+ }