Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: pegar celular e telefone, diminuido timeout pra carregar #186

Merged
merged 3 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions api/src/Controllers/PerguntaSugeridaController.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,12 @@ private function createValidationErrors(array $data): array
$errors[] = "e-mail inválido";
}

if (empty($data["telefone"])) {
$errors[] = "celular é obrigatório";
} else if (!preg_match("/^\d{11,}$/", $data["telefone"])) {
$errors[] = "celular deve ter 11 dígitos";
$numeroLimpo = preg_replace("/[^0-9]/", "", $data["telefone"]);

if (empty($numeroLimpo)) {
$errors[] = "telefone é obrigatório";
} else if (strlen($numeroLimpo) < 10 || strlen($numeroLimpo) > 11) {
$errors[] = "telefone deve ter 10 ou 11 dígitos";
}

if (empty($data["pergunta"])) {
Expand Down
3 changes: 2 additions & 1 deletion api/src/Gateways/PerguntaGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ public function getAll(array $ordenacao, $pagina = 1, $qtdPorPg = 10, $order = "
CASE
WHEN prioridade = 'Alta' THEN 1
WHEN prioridade = 'Normal' THEN 2
END
END,
p.atualizado_em DESC
LIMIT :limit OFFSET :offset";
}

Expand Down
4 changes: 2 additions & 2 deletions sistema/colaboradores/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ formCriarConta.addEventListener('submit', async function (event) {

setTimeout(() => {
window.location.reload();
}, 1000);
}, 500);
} catch (error) {
toast(error.message, true);
console.error(error);
Expand Down Expand Up @@ -327,7 +327,7 @@ const execute = async () => {

setTimeout(() => {
window.location.reload();
}, 1000);
}, 500);
} catch (error) {
toast(error.message, true);
}
Expand Down
4 changes: 2 additions & 2 deletions sistema/perguntas/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
<span>Email</span>
</th>
<th>
<span>Celular</span>
<span>Telefone</span>
</th>
<th id="pergunta">
<span>Sugestão</span>
Expand Down Expand Up @@ -172,4 +172,4 @@
</main>
</body>

</html>
</html>
6 changes: 3 additions & 3 deletions sistema/perguntas/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ const execute = async () => {

setTimeout(() => {
window.location = `${serverUrl}/sistema/perguntas`;
}, 1000);
}, 500);
};

form.addEventListener('submit', async function (event) {
Expand All @@ -158,7 +158,7 @@ const execute = async () => {

setTimeout(() => {
window.location.reload();
}, 1000);
}, 500);
} catch (error) {
toast('Houve um problema ao atualizar a sugestão', true);
console.log(error);
Expand Down Expand Up @@ -194,7 +194,7 @@ const execute = async () => {

setTimeout(() => {
window.location.reload();
}, 1000);
}, 500);
} else {
botaoEnviar.disabled = false;
botaoEnviar.textContent = 'Adicionar';
Expand Down
4 changes: 2 additions & 2 deletions sugestoes/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
<input type="email" id="email" name="email" required placeholder="Digite seu e-mail" />
</div>
<div>
<label for="telefone">Celular</label>
<input type="tel" id="phone" name="telefone" required placeholder="Digite seu celular" />
<label for="telefone">Telefone</label>
<input type="tel" id="phone" name="telefone" required placeholder="Digite seu telefone ou celular" />
</div>
</div>
<div class="duvida-sugestao">
Expand Down
52 changes: 25 additions & 27 deletions sugestoes/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,94 +6,93 @@ const botao = document.querySelector('.botao');

const nome = form.querySelector('#nome');
const email = form.querySelector('#email');
const celular = form.querySelector('#phone');
const telefone = form.querySelector('#phone');
const pergunta = form.querySelector('#mensagem');

VMasker(celular).maskPattern('(99) 9-9999-9999');
telefone.addEventListener('input', function (e) {
if (e.target.value.replace(/\D/g, '').length < 11) {
VMasker(telefone).maskPattern('(99) 9999-9999');
} else {
VMasker(telefone).maskPattern('(99) 9-9999-9999');
}
});

form.addEventListener('submit', async (e) => {
e.preventDefault();
VMasker(celular).unMask();

spinner.classList.toggle('mostrar');
botao.classList.toggle('mostrar');

if (nome.value.length < 3) {
toast('Nome precisa de no mínimo 3 caracteres', true);

spinner.classList.toggle('mostrar');
botao.classList.toggle('mostrar');
VMasker(celular).maskPattern('(99) 9-9999-9999');

return;
} else if (nome.value.length > 100) {
toast('Nome máximo permitido 100 caracteres', true);

spinner.classList.toggle('mostrar');
botao.classList.toggle('mostrar');
VMasker(celular).maskPattern('(99) 9-9999-9999');

return;
}

if (!validator.isEmail(email.value.trim())) {
toast('Digite um e-mail válido', true);

spinner.classList.toggle('mostrar');
botao.classList.toggle('mostrar');
VMasker(celular).maskPattern('(99) 9-9999-9999');

return;
}

if (!celular.value.trim()) {
toast('Celular obrigatório', true);

if (!telefone.value.trim()) {
toast('telefone obrigatório', true);
spinner.classList.toggle('mostrar');
botao.classList.toggle('mostrar');
VMasker(celular).maskPattern('(99) 9-9999-9999');
return;
} else if (celular.value.length !== 11) {
toast('Celular deve ter 11 dígitos', true);

return;
} else if (
telefone.value.replace(/\D/g, '').length < 10 ||
telefone.value.replace(/\D/g, '').length > 11
) {
toast('telefone deve ter 10 ou 11 dígitos', true);
spinner.classList.toggle('mostrar');
botao.classList.toggle('mostrar');
VMasker(celular).maskPattern('(99) 9-9999-9999');
return;
}

if (pergunta.value.length < 10) {
toast('Dúvida precisa de no mínimo 10 caracteres', true);

spinner.classList.toggle('mostrar');
botao.classList.toggle('mostrar');
VMasker(celular).maskPattern('(99) 9-9999-9999');

return;
} else if (pergunta.value.length > 2000) {
toast('Dúvida máximo permitido 2000 caracteres', true);

spinner.classList.toggle('mostrar');
botao.classList.toggle('mostrar');
VMasker(celular).maskPattern('(99) 9-9999-9999');

return;
}

nome.disabled = true;
email.disabled = true;
celular.disabled = true;
telefone.disabled = true;
pergunta.disabled = true;

setTimeout(async () => {
try {
const sugestaoCriada = await criarSugestao({
nome: nome.value,
email: email.value,
telefone: celular.value,
telefone: telefone.value,
pergunta: pergunta.value,
});

if (sugestaoCriada) {
toast('Sugestão enviada com sucesso');
nome.value = '';
email.value = '';
celular.value = '';
telefone.value = '';
pergunta.value = '';
} else {
toast('Houve um erro ao criar a sugestão', true);
Expand All @@ -103,12 +102,11 @@ form.addEventListener('submit', async (e) => {
toast(erro, true);
});
} finally {
VMasker(celular).maskPattern('(99) 9-9999-9999');
spinner.classList.toggle('mostrar');
botao.classList.toggle('mostrar');
nome.disabled = false;
email.disabled = false;
celular.disabled = false;
telefone.disabled = false;
pergunta.disabled = false;
}
}, 1000);
Expand Down