Skip to content

Commit

Permalink
Merge pull request #43 from deniodev/dev
Browse files Browse the repository at this point in the history
Add 258 prefix to the  phone number
  • Loading branch information
deniodev authored Jun 11, 2024
2 parents cef52aa + 4cca97a commit 88cc745
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 13 deletions.
4 changes: 2 additions & 2 deletions client/src/i18n/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@
"servicename": "Type your service name here.",
"city": "City",
"selectcity": "Select City",
"phone": "Phone",
"whatsaap": "Type your WhatsApp number eg: 258848090100",
"phone": "Phone (WhatsApp)",
"whatsaap": "eg: 848090100",
"description": "Description",
"description1": "Add a description of your service.",
"title": "Title",
Expand Down
6 changes: 3 additions & 3 deletions client/src/i18n/translations/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@
"servicename": "Digite o nome do seu serviço aqui.",
"city": "Cidade",
"selectcity": "Selecione Cidade",
"phone": "Telefone",
"whatsaap": "Digite seu número de WhatsApp ex: 258848090100",
"phone": "Telefone (WhatsApp)",
"whatsaap": " Ex: 848090100",
"description": "Descrição",
"description1": "Adicione a descrição do seu serviço.",
"title": "Título",
"title1": "Digite o título do seu serviço aqui.",
"title1": "Ex: Electricista",
"category": "Categoria",
"selectcategory": "Selecione a Categoria",
"coverimg": "Imagem de Capa",
Expand Down
24 changes: 20 additions & 4 deletions client/src/pages/CreateService.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,29 @@ const CreateService = () => {
};

const handleChange = (e) => {
setFormData({
...formData,
[e.target.id]: e.target.value,
});
const { id, value } = e.target;
if (id === 'phone') {
const digitsOnly = value.replace(/\D/g, '');
setFormData({
...formData,
[id]: digitsOnly,
});
} else {
setFormData({
...formData,
[id]: value,
});
}
};

const handleSubmit = async (e) => {
e.preventDefault();

let updatedPhone = formData.phone;
if (!updatedPhone.startsWith('258')) {
updatedPhone = `258${updatedPhone}`;
}

try {
if (formData.imageUrls.length < 1)
return setError('You must upload at least one image');
Expand All @@ -151,6 +166,7 @@ const CreateService = () => {
},
body: JSON.stringify({
...formData,
phone: updatedPhone,
userRef: currentUser._id,
}),
});
Expand Down
23 changes: 19 additions & 4 deletions client/src/pages/UpdateService.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,22 @@ const UpdateService = () => {
};

const handleChange = (e) => {
setFormData({
...formData,
[e.target.id]: e.target.value,
});
const { id, value } = e.target;
if (id === 'phone') {
const digitsOnly = value.replace(/\D/g, '');
const phoneWithPrefix = digitsOnly.startsWith('258')
? digitsOnly
: `258${digitsOnly}`;
setFormData({
...formData,
[id]: phoneWithPrefix,
});
} else {
setFormData({
...formData,
[id]: value,
});
}
};

const handleSubmit = async (e) => {
Expand All @@ -167,6 +179,9 @@ const UpdateService = () => {
},
body: JSON.stringify({
...formData,
phone: formData.phone.startsWith('258')
? formData.phone
: `258${formData.phone}`,
userRef: currentUser._id,
}),
});
Expand Down

0 comments on commit 88cc745

Please sign in to comment.