mirror of
https://github.com/emailerfacu-spec/minix-front.git
synced 2026-04-01 13:10:44 -03:00
@@ -8,6 +8,7 @@
|
||||
import Spinner from '../ui/spinner/spinner.svelte';
|
||||
import { register } from '@/hooks/register';
|
||||
import type { RegisterDto } from '../../../types';
|
||||
import { invalidate } from '$app/navigation';
|
||||
|
||||
interface Prop {
|
||||
open: boolean;
|
||||
@@ -29,9 +30,18 @@
|
||||
cargando = true;
|
||||
error = '';
|
||||
|
||||
await register(e, dto, () => {
|
||||
error = 'Error al registrar el usuario';
|
||||
});
|
||||
await register(
|
||||
e,
|
||||
dto,
|
||||
() => {
|
||||
error = 'Error al registrar el usuario';
|
||||
},
|
||||
true
|
||||
);
|
||||
if (error == '') {
|
||||
invalidate('admin:load');
|
||||
open = false;
|
||||
}
|
||||
|
||||
cargando = false;
|
||||
}
|
||||
@@ -57,11 +67,7 @@
|
||||
</InputGroup>
|
||||
|
||||
<InputGroup>
|
||||
<InputGroupInput
|
||||
type="email"
|
||||
disabled={cargando}
|
||||
bind:value={dto.email}
|
||||
/>
|
||||
<InputGroupInput type="email" disabled={cargando} bind:value={dto.email} />
|
||||
<InputGroupAddon>Email</InputGroupAddon>
|
||||
</InputGroup>
|
||||
|
||||
@@ -71,11 +77,7 @@
|
||||
</InputGroup>
|
||||
|
||||
<InputGroup>
|
||||
<InputGroupInput
|
||||
type="password"
|
||||
disabled={cargando}
|
||||
bind:value={dto.password}
|
||||
/>
|
||||
<InputGroupInput type="password" disabled={cargando} bind:value={dto.password} />
|
||||
<InputGroupAddon>Contraseña</InputGroupAddon>
|
||||
</InputGroup>
|
||||
|
||||
@@ -90,11 +92,7 @@
|
||||
{/if}
|
||||
</Button>
|
||||
|
||||
<Button
|
||||
variant="secondary"
|
||||
disabled={cargando}
|
||||
onclick={() => (open = false)}
|
||||
>
|
||||
<Button variant="secondary" disabled={cargando} onclick={() => (open = false)}>
|
||||
Cancelar
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
import Label from '@/components/ui/label/label.svelte';
|
||||
import { resolve } from '$app/paths';
|
||||
import { busquedaHashtags } from '@/hooks/busquedaHashtags';
|
||||
import Separator from '@/components/ui/separator/separator.svelte';
|
||||
|
||||
let search: string = $state('');
|
||||
let open = $state(false);
|
||||
@@ -55,16 +56,18 @@
|
||||
<svelte:document onkeydown={handleKeydown} />
|
||||
|
||||
<InputGroup class="group">
|
||||
<InputGroupAddon align="inline-start"><Search /></InputGroupAddon>
|
||||
<InputGroupAddon class="me-3" align="inline-start"><Search /></InputGroupAddon>
|
||||
<Separator orientation="vertical"></Separator>
|
||||
|
||||
<InputGroupInput
|
||||
type="text"
|
||||
placeholder="Buscar Usuario o Hashtag"
|
||||
bind:value={search}
|
||||
oninput={() => (open = true)}
|
||||
class="max-w-0 transition-[max-width] duration-1000 ease-out group-hover:max-w-xs focus:max-w-xs"
|
||||
class="max-w-0 p-1! transition-[max-width] duration-1000 ease-out group-hover:max-w-xs focus:max-w-xs"
|
||||
/>
|
||||
<InputGroupAddon align="inline-end" class="flex gap-0">
|
||||
<Kbd>Ctrl</Kbd>+<Kbd>K</Kbd>
|
||||
<InputGroupAddon align="inline-end">
|
||||
<Kbd>Ctrl+K</Kbd>
|
||||
</InputGroupAddon>
|
||||
</InputGroup>
|
||||
<CommandDialog bind:open>
|
||||
|
||||
@@ -52,14 +52,14 @@
|
||||
<div class="flex items-center">
|
||||
<a href="/" class="mr-6 flex items-center space-x-2">
|
||||
<Avatar
|
||||
class="transform rounded-sm! transition-transform duration-300 ease-in-out hover:scale-130 hover:rotate-12"
|
||||
class="h-8 w-8 transform rounded-sm! transition-transform duration-300 ease-in-out hover:scale-130 hover:rotate-12"
|
||||
>
|
||||
<AvatarImage src="/x.png" alt="minix" />
|
||||
</Avatar>
|
||||
</a>
|
||||
<nav class="me-2 items-center space-x-6 text-sm font-medium md:flex">
|
||||
<!-- <nav class="me-2 items-center space-x-6 text-sm font-medium md:flex">
|
||||
<ButtonTheme />
|
||||
</nav>
|
||||
</nav> -->
|
||||
</div>
|
||||
|
||||
<!-- Desktop menu -->
|
||||
|
||||
@@ -1,36 +1,38 @@
|
||||
import { apiBase } from "@/stores/url";
|
||||
import { goto } from "$app/navigation";
|
||||
import type { RegisterDto } from "../../types";
|
||||
import { apiBase } from '@/stores/url';
|
||||
import { goto } from '$app/navigation';
|
||||
import type { RegisterDto } from '../../types';
|
||||
import { get } from 'svelte/store';
|
||||
|
||||
export async function register(e: SubmitEvent, dto: RegisterDto, callbackfn:()=>void){
|
||||
e.preventDefault();
|
||||
if (dto.password == "" || dto.username == "" ||
|
||||
!dto.email?.includes("@") || dto.displayName=="") return;
|
||||
try {
|
||||
|
||||
const { subscribe } = apiBase;
|
||||
let baseUrl: string = '';
|
||||
|
||||
subscribe((value) => {
|
||||
baseUrl = value;
|
||||
})();
|
||||
const req = await fetch(baseUrl + "/api/auth/register", {
|
||||
method: "POST",
|
||||
headers:{
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
body: JSON.stringify(dto)
|
||||
});
|
||||
if (req.ok) {
|
||||
const data= await req.json();
|
||||
goto("/login?msg="+data.message);
|
||||
} else {
|
||||
callbackfn();
|
||||
}
|
||||
|
||||
} catch {
|
||||
callbackfn();
|
||||
console.error("fallo al intentar alcanzar el servidor")
|
||||
|
||||
}
|
||||
export async function register(
|
||||
e: SubmitEvent,
|
||||
dto: RegisterDto,
|
||||
callbackfn: () => void,
|
||||
admin: boolean = false
|
||||
) {
|
||||
e.preventDefault();
|
||||
if (
|
||||
dto.password == '' ||
|
||||
dto.username == '' ||
|
||||
!dto.email?.includes('@') ||
|
||||
dto.displayName == ''
|
||||
)
|
||||
return;
|
||||
try {
|
||||
const req = await fetch(get(apiBase) + '/api/auth/register', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify(dto)
|
||||
});
|
||||
if (req.ok) {
|
||||
const data = await req.json();
|
||||
if (!admin) goto('/login?msg=' + data.message);
|
||||
} else {
|
||||
callbackfn();
|
||||
}
|
||||
} catch {
|
||||
callbackfn();
|
||||
console.error('fallo al intentar alcanzar el servidor');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
import { dev } from '$app/environment';
|
||||
import { readable } from 'svelte/store';
|
||||
|
||||
// export const apiBase = readable(
|
||||
// dev ? 'http://localhost:5000' : 'https://minix-back-dsuk.onrender.com'
|
||||
// );
|
||||
|
||||
export const apiBase = readable(
|
||||
dev ? 'http://localhost:5000' : 'https://minix-back-dsuk.onrender.com'
|
||||
dev
|
||||
? 'http://localhost:5000'
|
||||
: 'https://minix-back-3.salmonpebble-66858787.brazilsouth.azurecontainerapps.io'
|
||||
);
|
||||
|
||||
@@ -6,14 +6,21 @@
|
||||
import TablaUsuarios from '@/components/TablaUsuarios.svelte';
|
||||
import CardTitle from '@/components/ui/card/card-title.svelte';
|
||||
import CardHeader from '@/components/ui/card/card-header.svelte';
|
||||
import type { UserResponseDto } from '../../../types';
|
||||
|
||||
let cargando = $state(true);
|
||||
let usuarios = $state(page.data.usuarios);
|
||||
interface Prop {
|
||||
data: {
|
||||
usuarios?: UserResponseDto[];
|
||||
error: boolean;
|
||||
};
|
||||
}
|
||||
|
||||
let { data }: Prop = $props();
|
||||
</script>
|
||||
|
||||
<div class="flex min-h-fit w-full items-center justify-center p-6 md:p-10">
|
||||
<div class="w-full max-w-6xl">
|
||||
<Card class={page.data.error ? 'border-red-400' : ''}>
|
||||
<Card class={data.error ? 'border-red-400' : ''}>
|
||||
<CardHeader class="w-full">
|
||||
<CardTitle class="rounded-full bg-accent-foreground/10">
|
||||
<h1 class="mt-3 mb-4 scroll-m-20 text-center text-2xl font-extrabold tracking-tight">
|
||||
@@ -22,12 +29,10 @@
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
{#if page.data.usuarios.length === 0}
|
||||
{#if data.usuarios?.length === 0}
|
||||
<CardDescription>No hay usuarios que mostar</CardDescription>
|
||||
{:else}
|
||||
{#key page.data.usuarios}
|
||||
<TablaUsuarios bind:usuarios></TablaUsuarios>
|
||||
{/key}
|
||||
<TablaUsuarios usuarios={data.usuarios || []}></TablaUsuarios>
|
||||
{/if}
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
2
src/types.d.ts
vendored
2
src/types.d.ts
vendored
@@ -1,5 +1,4 @@
|
||||
export interface Post {
|
||||
_id: string;
|
||||
id: string;
|
||||
authorId: string;
|
||||
authorDisplayName: string;
|
||||
@@ -76,6 +75,7 @@ export interface PostResponseDto {
|
||||
isEdited: boolean;
|
||||
visibility: string;
|
||||
hashtags: string[]?;
|
||||
isLiked: boolean?;
|
||||
}
|
||||
|
||||
export interface UserResponseDto {
|
||||
|
||||
Reference in New Issue
Block a user