pukaad-ui-lib 1.254.0 → 1.255.0

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/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "pukaad-ui-lib",
3
3
  "configKey": "pukaadUI",
4
- "version": "1.254.0",
4
+ "version": "1.255.0",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "3.6.1"
@@ -1,14 +1,14 @@
1
1
  <template>
2
- <InputTextField
3
- ref="inputTextFieldRef"
4
- v-bind="props"
5
- :rules="props.rules || defaultRules"
6
- v-model="modelValue"
7
- >
8
- <template v-for="(_, name) in $slots" v-slot:[name]="slotData">
9
- <slot :name="name" v-bind="slotData || {}" />
10
- </template>
11
- </InputTextField>
2
+ <InputTextField
3
+ ref="inputTextFieldRef"
4
+ v-bind="props"
5
+ :rules="props.rules || defaultRules"
6
+ v-model="modelValue"
7
+ >
8
+ <template v-for="(_, name) in $slots" v-slot:[name]="slotData">
9
+ <slot :name="name" v-bind="slotData || {}" />
10
+ </template>
11
+ </InputTextField>
12
12
  </template>
13
13
 
14
14
  <script setup>
@@ -45,6 +45,11 @@ const modalProps = computed(() => ({
45
45
  phoneOTP: {
46
46
  phone: phone.value,
47
47
  phoneLabel: maskedPhone.value,
48
+ requestPath: "/auth/forgot-password/send-otp",
49
+ requestBody: { phone: phone.value, method: "sms" },
50
+ verifyPath: "/auth/forgot-password/verify-otp",
51
+ verifyBody: { phone: phone.value },
52
+ initialExpiredTime: expiredTime.value,
48
53
  confirmedText: "\u0E16\u0E31\u0E14\u0E44\u0E1B"
49
54
  },
50
55
  emailOTP: {
@@ -74,7 +79,13 @@ const handleComplete = async (key, data) => {
74
79
  return;
75
80
  }
76
81
  if (key === "phoneOTP") {
77
- await callVerifyOTP(data);
82
+ const token = data?.reset_token;
83
+ if (!token) {
84
+ $toast?.error?.("\u0E44\u0E21\u0E48\u0E1E\u0E1A reset token");
85
+ return;
86
+ }
87
+ resetToken.value = token;
88
+ modalStates.passwordNew = true;
78
89
  return;
79
90
  }
80
91
  if (key === "emailOTP") {
@@ -114,22 +125,6 @@ const callSendOTP = async () => {
114
125
  isLoading.value = false;
115
126
  }
116
127
  };
117
- const callVerifyOTP = async (code) => {
118
- isLoading.value = true;
119
- try {
120
- const res = await api("/auth/forgot-password/verify-otp", {
121
- method: "POST",
122
- body: { phone: phone.value, code }
123
- });
124
- resetToken.value = res.data.reset_token;
125
- modalStates.passwordNew = true;
126
- } catch (e) {
127
- const msg = e?.data?.message?.description || e?.data?.message || "OTP \u0E44\u0E21\u0E48\u0E16\u0E39\u0E01\u0E15\u0E49\u0E2D\u0E07\u0E2B\u0E23\u0E37\u0E2D\u0E2B\u0E21\u0E14\u0E2D\u0E32\u0E22\u0E38";
128
- $toast?.error?.(msg);
129
- } finally {
130
- isLoading.value = false;
131
- }
132
- };
133
128
  watch(isOpen, (v) => {
134
129
  if (v) {
135
130
  phone.value = "";
@@ -8,11 +8,11 @@ declare const __VLS_export: import("vue").DefineComponent<__VLS_PublicProps, {},
8
8
  "update:modelValue": (value: boolean) => any;
9
9
  } & {
10
10
  close: () => any;
11
- complete: (value: string) => any;
11
+ complete: (data?: any) => any;
12
12
  }, string, import("vue").PublicProps, Readonly<__VLS_PublicProps> & Readonly<{
13
13
  onClose?: (() => any) | undefined;
14
14
  "onUpdate:modelValue"?: ((value: boolean) => any) | undefined;
15
- onComplete?: ((value: string) => any) | undefined;
15
+ onComplete?: ((data?: any) => any) | undefined;
16
16
  }>, {
17
17
  phone: string;
18
18
  confirmedText: string;
@@ -13,6 +13,7 @@
13
13
  <InputOTP name="otp" columnGap="auto" v-model="valueOTP" :error="otpError" />
14
14
  </div>
15
15
 
16
+
16
17
  <div class="text-center font-body-large">
17
18
  <template v-if="countdown !== '00:00'">
18
19
  กรุณารอ <span class="text-primary">{{ countdown }}</span> นาที
@@ -26,7 +27,7 @@
26
27
  </div>
27
28
 
28
29
  <template #footer="{ meta }">
29
- <Button type="submit" color="primary" :disabled="!meta.valid" class="w-full">
30
+ <Button type="submit" color="primary" :disabled="!meta.valid || isLoading" class="w-full">
30
31
  {{ props.confirmedText }}
31
32
  </Button>
32
33
  </template>
@@ -35,12 +36,19 @@
35
36
 
36
37
  <script setup>
37
38
  import { ref, watch } from "vue";
39
+ import { useNuxtApp } from "nuxt/app";
40
+ import { useApi } from "../../composables/useApi";
38
41
  import { useCountDown } from "../../composables/useCountDown";
39
42
  const emit = defineEmits(["complete", "close"]);
40
43
  const props = defineProps({
41
44
  phoneLabel: { type: String, required: false, default: "" },
42
45
  phone: { type: String, required: false, default: "" },
43
46
  confirmedText: { type: String, required: false, default: "\u0E22\u0E37\u0E19\u0E22\u0E31\u0E19" },
47
+ requestPath: { type: String, required: false },
48
+ requestBody: { type: Object, required: false },
49
+ verifyPath: { type: String, required: false },
50
+ verifyBody: { type: Object, required: false },
51
+ initialExpiredTime: { type: String, required: false },
44
52
  name: { type: String, required: false },
45
53
  type: { type: String, required: false },
46
54
  gap: { type: Number, required: false },
@@ -49,33 +57,77 @@ const props = defineProps({
49
57
  placeholder: { type: String, required: false }
50
58
  });
51
59
  const isOpen = defineModel({ type: Boolean, ...{ default: false } });
60
+ const { $toast } = useNuxtApp();
61
+ const api = useApi();
52
62
  const textRef = ref("");
53
63
  const valueOTP = ref("");
54
64
  const otpError = ref("");
65
+ const isLoading = ref(false);
55
66
  const { CountdownTime } = useCountDown();
56
67
  const expireAt = ref("");
57
68
  const countdown = CountdownTime(expireAt);
58
- const resetCountdown = () => {
59
- expireAt.value = new Date(Date.now() + 5 * 60 * 1e3).toISOString();
69
+ const handleSendOTP = async () => {
70
+ try {
71
+ isLoading.value = true;
72
+ const path = props.requestPath ?? "/me/phone-otp-request";
73
+ const body = props.requestBody ?? { phone: props.phone };
74
+ if (!props.requestBody && !props.phone) {
75
+ throw new Error("\u0E01\u0E23\u0E38\u0E13\u0E32\u0E23\u0E30\u0E1A\u0E38 phone");
76
+ }
77
+ const response = await api(path, {
78
+ method: "POST",
79
+ body
80
+ });
81
+ if (response?.data?.expired_time) {
82
+ expireAt.value = response.data.expired_time;
83
+ } else {
84
+ expireAt.value = new Date(Date.now() + 5 * 60 * 1e3).toISOString();
85
+ }
86
+ if (response?.data?.ref) {
87
+ textRef.value = response.data.ref;
88
+ }
89
+ } catch (err) {
90
+ const msg = err?.data?.message?.description || err?.data?.message || "\u0E1E\u0E1A\u0E02\u0E49\u0E2D\u0E1C\u0E34\u0E14\u0E1E\u0E25\u0E32\u0E14\u0E43\u0E19\u0E01\u0E32\u0E23\u0E2A\u0E48\u0E07 OTP";
91
+ $toast?.error?.(msg);
92
+ } finally {
93
+ isLoading.value = false;
94
+ }
60
95
  };
61
96
  const onResend = () => {
62
97
  valueOTP.value = "";
63
98
  otpError.value = "";
64
- resetCountdown();
99
+ handleSendOTP();
65
100
  };
66
- const onVerifyOTP = () => {
67
- if (valueOTP.value === "123456") {
101
+ const onVerifyOTP = async () => {
102
+ try {
103
+ isLoading.value = true;
104
+ const path = props.verifyPath ?? "/me/phone-otp-verify";
105
+ const body = props.verifyBody ? { ...props.verifyBody, code: valueOTP.value } : { code: valueOTP.value, phone: props.phone };
106
+ const response = await api(path, {
107
+ method: "POST",
108
+ body
109
+ });
68
110
  otpError.value = "";
69
- emit("complete", valueOTP.value);
111
+ emit("complete", response?.data || valueOTP.value);
70
112
  isOpen.value = false;
71
- } else {
113
+ } catch (err) {
72
114
  otpError.value = "\u0E23\u0E2B\u0E31\u0E2A\u0E22\u0E37\u0E19\u0E22\u0E31\u0E19\u0E44\u0E21\u0E48\u0E16\u0E39\u0E01\u0E15\u0E49\u0E2D\u0E07";
115
+ } finally {
116
+ isLoading.value = false;
73
117
  }
74
118
  };
75
119
  watch(isOpen, (value) => {
76
120
  textRef.value = "";
77
121
  valueOTP.value = "";
78
122
  otpError.value = "";
79
- if (value) resetCountdown();
123
+ if (value) {
124
+ if (props.initialExpiredTime) {
125
+ expireAt.value = props.initialExpiredTime;
126
+ } else {
127
+ handleSendOTP();
128
+ }
129
+ } else {
130
+ expireAt.value = "";
131
+ }
80
132
  });
81
133
  </script>
@@ -8,11 +8,11 @@ declare const __VLS_export: import("vue").DefineComponent<__VLS_PublicProps, {},
8
8
  "update:modelValue": (value: boolean) => any;
9
9
  } & {
10
10
  close: () => any;
11
- complete: (value: string) => any;
11
+ complete: (data?: any) => any;
12
12
  }, string, import("vue").PublicProps, Readonly<__VLS_PublicProps> & Readonly<{
13
13
  onClose?: (() => any) | undefined;
14
14
  "onUpdate:modelValue"?: ((value: boolean) => any) | undefined;
15
- onComplete?: ((value: string) => any) | undefined;
15
+ onComplete?: ((data?: any) => any) | undefined;
16
16
  }>, {
17
17
  phone: string;
18
18
  confirmedText: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pukaad-ui-lib",
3
- "version": "1.254.0",
3
+ "version": "1.255.0",
4
4
  "description": "pukaad-ui for MeMSG",
5
5
  "repository": {
6
6
  "type": "git",