Skip to content

Commit 084a97d

Browse files
committed
Merge branch 'fix/phone-parser-storage' into chore/all-my-stuffs
2 parents c623458 + c6adf16 commit 084a97d

File tree

4 files changed

+66
-6
lines changed

4 files changed

+66
-6
lines changed

components.d.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,10 @@ declare module '@vue/runtime-core' {
129129
MenuLayout: typeof import('./src/components/MenuLayout.vue')['default']
130130
MetaTagGenerator: typeof import('./src/tools/meta-tag-generator/meta-tag-generator.vue')['default']
131131
MimeTypes: typeof import('./src/tools/mime-types/mime-types.vue')['default']
132+
NA: typeof import('naive-ui')['NA']
132133
NavbarButtons: typeof import('./src/components/NavbarButtons.vue')['default']
133-
NCheckbox: typeof import('naive-ui')['NCheckbox']
134+
NButton: typeof import('naive-ui')['NButton']
135+
NCode: typeof import('naive-ui')['NCode']
134136
NCollapseTransition: typeof import('naive-ui')['NCollapseTransition']
135137
NConfigProvider: typeof import('naive-ui')['NConfigProvider']
136138
NDivider: typeof import('naive-ui')['NDivider']
@@ -141,7 +143,8 @@ declare module '@vue/runtime-core' {
141143
NLayout: typeof import('naive-ui')['NLayout']
142144
NLayoutSider: typeof import('naive-ui')['NLayoutSider']
143145
NMenu: typeof import('naive-ui')['NMenu']
144-
NSpace: typeof import('naive-ui')['NSpace']
146+
NScrollbar: typeof import('naive-ui')['NScrollbar']
147+
NSpin: typeof import('naive-ui')['NSpin']
145148
NTable: typeof import('naive-ui')['NTable']
146149
NumeronymGenerator: typeof import('./src/tools/numeronym-generator/numeronym-generator.vue')['default']
147150
OtpCodeGeneratorAndValidator: typeof import('./src/tools/otp-code-generator-and-validator/otp-code-generator-and-validator.vue')['default']

locales/en.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ tools:
299299

300300
phone-parser-and-formatter:
301301
title: Phone parser and formatter
302-
description: Parse, validate and format phone numbers. Get information about the phone number, like the country code, type, etc.
302+
description: Parse, validate and format phone numbers. Get information about the phone number, like the country code, type, etc. Forge link to send message in WhatsApp and SMS.
303303

304304
ipv4-subnet-calculator:
305305
title: IPv4 subnet calculator

src/tools/phone-parser-and-formatter/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ export const tool = defineTool({
1818
'cell',
1919
'international',
2020
'national',
21+
'whatsapp',
22+
'sms',
23+
'message',
2124
],
2225
component: () => import('./phone-parser-and-formatter.vue'),
2326
icon: Phone,

src/tools/phone-parser-and-formatter/phone-parser-and-formatter.vue

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ import {
99
import { withDefaultOnError } from '@/utils/defaults';
1010
import { booleanToHumanReadable } from '@/utils/boolean';
1111
import { useValidation } from '@/composable/validation';
12+
import { useQueryParamOrStorage } from '@/composable/queryParams';
1213
1314
const rawPhone = ref('');
14-
const defaultCountryCode = ref(getDefaultCountryCode());
15+
const defaultCountryCode = useQueryParamOrStorage({ name: 'country', storageName: 'phone-parser:country', defaultValue: getDefaultCountryCode() });
1516
const validation = useValidation({
1617
source: rawPhone,
1718
rules: [
@@ -22,13 +23,16 @@ const validation = useValidation({
2223
],
2324
});
2425
25-
const parsedDetails = computed(() => {
26+
const parsedRaw = computed(() => {
2627
if (!validation.isValid) {
2728
return undefined;
2829
}
2930
30-
const parsed = withDefaultOnError(() => parsePhoneNumber(rawPhone.value, defaultCountryCode.value), undefined);
31+
return withDefaultOnError(() => parsePhoneNumber(rawPhone.value, defaultCountryCode.value), undefined);
32+
});
3133
34+
const parsedDetails = computed(() => {
35+
const parsed = parsedRaw.value;
3236
if (!parsed) {
3337
return undefined;
3438
}
@@ -81,6 +85,27 @@ const countriesOptions = getCountries().map(code => ({
8185
label: `${lookup.byIso(code)?.country || code} (+${getCountryCallingCode(code)})`,
8286
value: code,
8387
}));
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+
});
84109
</script>
85110

86111
<template>
@@ -110,5 +135,34 @@ const countriesOptions = getCountries().map(code => ({
110135
</tr>
111136
</tbody>
112137
</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>
113167
</div>
114168
</template>

0 commit comments

Comments
 (0)