@@ -23,13 +23,16 @@ const validation = useValidation({
23
23
],
24
24
});
25
25
26
- const parsedDetails = computed (() => {
26
+ const parsedRaw = computed (() => {
27
27
if (! validation .isValid ) {
28
28
return undefined ;
29
29
}
30
30
31
- const parsed = withDefaultOnError (() => parsePhoneNumber (rawPhone .value , defaultCountryCode .value ), undefined );
31
+ return withDefaultOnError (() => parsePhoneNumber (rawPhone .value , defaultCountryCode .value ), undefined );
32
+ });
32
33
34
+ const parsedDetails = computed (() => {
35
+ const parsed = parsedRaw .value ;
33
36
if (! parsed ) {
34
37
return undefined ;
35
38
}
@@ -82,6 +85,27 @@ const countriesOptions = getCountries().map(code => ({
82
85
label: ` ${lookup .byIso (code )?.country || code } (+${getCountryCallingCode (code )}) ` ,
83
86
value: code ,
84
87
}));
88
+
89
+ const messageToSend = ref (' ' );
90
+ const whatsAppLink = computed (() => {
91
+ const parsed = parsedRaw .value ;
92
+ if (! parsed ) {
93
+ return undefined ;
94
+ }
95
+
96
+ const internationalNoPunts = parsed .formatInternational ().replace (/ ^ \+ 0* / g , ' ' ).replace (/ \D / g , ' ' );
97
+
98
+ return ` https://wa.me/${internationalNoPunts }?text=${encodeURIComponent (messageToSend .value )} ` ;
99
+ });
100
+ const smsLink = computed (() => {
101
+ const parsed = parsedRaw .value ;
102
+ if (! parsed ) {
103
+ return undefined ;
104
+ }
105
+
106
+ const internationalNoSpaces = parsed .formatInternational ().replace (/ \s / g , ' ' );
107
+ return ` sms:${internationalNoSpaces }&body=${encodeURIComponent (messageToSend .value )} ` ;
108
+ });
85
109
</script >
86
110
87
111
<template >
@@ -111,5 +135,34 @@ const countriesOptions = getCountries().map(code => ({
111
135
</tr >
112
136
</tbody >
113
137
</n-table >
138
+
139
+ <n-divider />
140
+
141
+ <c-input-text
142
+ v-model:value =" messageToSend"
143
+ multiline
144
+ rows =" 4"
145
+ placeholder =" Enter a message to send"
146
+ label =" Message to send:"
147
+ mb-2
148
+ />
149
+
150
+ <c-card v-if =" whatsAppLink" title =" WhatsApp Send link" mb-2 >
151
+ <input-copyable :value =" whatsAppLink" mb-2 />
152
+ <div flex justify-center >
153
+ <!-- //NOSONAR --> <c-button :href =" whatsAppLink" target =" _blank" >
154
+ Send via WhatsApp
155
+ </c-button >
156
+ </div >
157
+ </c-card >
158
+
159
+ <c-card v-if =" smsLink" title =" SMS Send link" >
160
+ <input-copyable :value =" smsLink" mb-2 />
161
+ <div flex justify-center >
162
+ <!-- //NOSONAR --> <c-button :href =" smsLink" target =" _blank" >
163
+ Send via SMS
164
+ </c-button >
165
+ </div >
166
+ </c-card >
114
167
</div >
115
168
</template >
0 commit comments