Merge branch 'dev' of github.com:emailerfacu-spec/minix-front into dev

This commit is contained in:
TroianoLuca
2025-12-04 00:09:04 -03:00
6 changed files with 126 additions and 13 deletions
+1 -1
View File
@@ -137,7 +137,7 @@
<Button <Button
variant="ghost" variant="ghost"
disabled={!$sesionStore?.accessToken} disabled={!$sesionStore?.accessToken}
class="flex items-center gap-2 rounded-full bg-accent p-3 text-lg" class={`${post.isLiked ? 'bg-blue-500/30' : 'bg-accent'} flex items-center gap-2 rounded-full p-3 text-lg`}
onclick={() => likeHandler()} onclick={() => likeHandler()}
> >
<p> <p>
@@ -85,7 +85,9 @@
Aceptar Aceptar
{/if} {/if}
</Button> </Button>
<Button variant="secondary" disabled={cargando}>Cerrar</Button> <Button variant="secondary" disabled={cargando} onclick={() => (open = !open)}
>Cerrar</Button
>
</div> </div>
</div> </div>
</form> </form>
+85 -6
View File
@@ -6,16 +6,50 @@
import type { RegisterDto } from '../../types'; import type { RegisterDto } from '../../types';
import { register } from '@/hooks/register'; import { register } from '@/hooks/register';
import Loader2Icon from '@lucide/svelte/icons/loader-2'; import Loader2Icon from '@lucide/svelte/icons/loader-2';
import Check from '@lucide/svelte/icons/check';
import Cross from '@lucide/svelte/icons/x';
import Spinner from './ui/spinner/spinner.svelte';
import { checkUsername } from '@/hooks/checkUsername';
import { checkEmail } from '@/hooks/checkEmail';
let { showAlert = $bindable() } = $props(); let { showAlert = $bindable() } = $props();
let cargando = $state(false); let cargando = $state(false);
const setAlert = () => (showAlert = true); let repetirContraseña = $state('');
let checkeandoUsuario: boolean | null = $state(null);
let esUsuarioValido = $state(false);
let checkeandoEmail: boolean | null = $state(null);
let esEmailValido = $state(false);
let dto: RegisterDto = $state({ password: '', username: '', email: '', displayName: '' }); let dto: RegisterDto = $state({ password: '', username: '', email: '', displayName: '' });
let coinsidenLasPass = $derived(repetirContraseña == dto.password);
const passwordRegex = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^A-Za-z0-9])[A-Za-z\d\W_]*$/;
let esContraseñaValida = $derived(passwordRegex.test(dto.password));
async function checkUsuario() {
checkeandoUsuario = true;
esUsuarioValido = await checkUsername(dto.username);
checkeandoUsuario = false;
}
async function checkEmaill() {
checkeandoEmail = true;
esEmailValido = await checkEmail(dto.email);
checkeandoEmail = false;
}
const setAlert = () => (showAlert = true);
const handleSubmit = async (e: SubmitEvent) => { const handleSubmit = async (e: SubmitEvent) => {
if (esUsuarioValido == false) return;
if (!coinsidenLasPass) return;
if (!esContraseñaValida) return;
cargando = true; cargando = true;
await register(e, dto, setAlert); await register(e, dto, setAlert);
cargando = false; cargando = false;
@@ -31,8 +65,26 @@
<form onsubmit={handleSubmit}> <form onsubmit={handleSubmit}>
<Field.Group> <Field.Group>
<Field.Field> <Field.Field>
<div class="flex justify-between">
<Field.Label for="name">Nombre de Usuario</Field.Label> <Field.Label for="name">Nombre de Usuario</Field.Label>
<Input id="name" bind:value={dto.username} type="text" placeholder="JPepe" required /> {#if checkeandoUsuario == null}
<div hidden></div>
{:else if checkeandoUsuario == true}
<Spinner></Spinner>
{:else if esUsuarioValido}
<Check class="text-green-500" />
{:else}
<Cross class="text-red-500" />
{/if}
</div>
<Input
id="name"
bind:value={dto.username}
type="text"
placeholder="JPepe"
required
onchange={checkUsuario}
/>
</Field.Field> </Field.Field>
<Field.Field> <Field.Field>
@@ -41,28 +93,55 @@
</Field.Field> </Field.Field>
<Field.Field> <Field.Field>
<div class="flex justify-between">
<Field.Label for="email">Email</Field.Label> <Field.Label for="email">Email</Field.Label>
{#if checkeandoEmail == null}
<div hidden></div>
{:else if checkeandoEmail == true}
<Spinner></Spinner>
{:else if esEmailValido}
<Check class="text-green-500" />
{:else}
<Cross class="text-red-500" />
{/if}
</div>
<Input <Input
id="email" id="email"
type="email" type="email"
bind:value={dto.email} bind:value={dto.email}
placeholder="m@ejemplo.com" placeholder="m@ejemplo.com"
required required
onchange={checkEmaill}
/> />
</Field.Field> </Field.Field>
<Field.Field> <Field.Field>
<Field.Label for="password">Contraseña</Field.Label> <Field.Label for="password">Contraseña</Field.Label>
<Input id="password" type="password" bind:value={dto.password} required /> <Input
<Field.Description>Debe de tener por lo menos 8 caracteres.</Field.Description> id="password"
type="password"
bind:value={dto.password}
required
class={{ 'border-red-500': dto.password && !esContraseñaValida }}
/>
<Field.Description
>Debe de tener por lo menos 8 caracteres, una minúscula, una mayúscula, un número y un
carácter especial.</Field.Description
>
</Field.Field> </Field.Field>
<Field.Field> <Field.Field>
<Field.Label for="confirm-password">Confirmar Contraseña</Field.Label> <Field.Label for="confirm-password">Confirmar Contraseña</Field.Label>
<Input id="confirm-password" type="password" required /> <Input
id="confirm-password"
type="password"
required
bind:value={repetirContraseña}
class={{ 'border-red-500': !coinsidenLasPass }}
/>
<Field.Description>Confirma la contraseña</Field.Description> <Field.Description>Confirma la contraseña</Field.Description>
</Field.Field> </Field.Field>
<Field.Group> <Field.Group>
<Field.Field> <Field.Field>
<Button type="submit" disabled={cargando}> <Button type="submit" disabled={cargando || !coinsidenLasPass || !esContraseñaValida}>
{#if cargando} {#if cargando}
Creando Cuenta... Creando Cuenta...
<Loader2Icon class="animate-spin" /> <Loader2Icon class="animate-spin" />
+16
View File
@@ -0,0 +1,16 @@
import { apiBase } from "@/stores/url";
import { get } from "svelte/store";
export async function checkEmail(email: string) {
try {
const req = await fetch(`${get(apiBase)}/api/users/check-email/${email}`, {
method: "GET"
});
if (req.ok){
return (await req.json()).available;
}
return false;
} catch {
return false;
}
}
+16
View File
@@ -0,0 +1,16 @@
import { apiBase } from "@/stores/url";
import { get } from "svelte/store";
export async function checkUsername(username: string) {
try {
const req = await fetch(`${get(apiBase)}/api/users/check-username/${username}`, {
method: "GET"
});
if (req.ok){
return (await req.json()).available;
}
return false;
} catch {
return false;
}
}
+3 -3
View File
@@ -47,10 +47,10 @@ export interface LoginDto {
} }
export interface RegisterDto { export interface RegisterDto {
username: string?; username: string;
email: string?; email: string;
password: string?; password: string?;
displayName: string?; displayName: string;
} }
export interface CreatePostDto { export interface CreatePostDto {