Skip to content

Commit

Permalink
Merge branch 'main' into feat/mapa-solicitar-ayuda
Browse files Browse the repository at this point in the history
  • Loading branch information
Roberto Milla Martinez committed Nov 8, 2024
2 parents 132279d + b6c92a4 commit 9be5a5f
Show file tree
Hide file tree
Showing 85 changed files with 1,867 additions and 1,946 deletions.
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
NEXT_PUBLIC_BASE_URL=https://ajudadana.es
NEXT_PUBLIC_NODE_ENV=production
NEXT_PUBLIC_SUPABASE_URL=
NEXT_PUBLIC_SUPABASE_ANON_KEY=
# this key is restricted in google
NEXT_PUBLIC_GOOGLE_KEY=

GEOCODING_API_KEY=
SUPABASE_GOOGLE_AUTH_ID=
SUPABASE_GOOGLE_AUTH_SECRET=
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,6 @@ node_modules/
/playwright-report/
/blob-report/
/playwright/.cache/

# Snaplet
/.snaplet/
66 changes: 51 additions & 15 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,33 +46,69 @@ Este mensaje indica que se han añadido instrucciones de instalación local en e

¡Gracias por contribuir! Tu ayuda hace una gran diferencia para el proyecto.

<br/>

## Desarrollo local - levantar db de desarrollo local

### Pre requisitos

- [docker](https://docs.docker.com/engine/install/) y [docker compose](https://docs.docker.com/compose/install/)
- [cli de supabase](https://supabase.com/docs/guides/local-development/cli/getting-started)
- [Docker](https://docs.docker.com/engine/install/) y [Docker Compose](https://docs.docker.com/compose/install/)
- [Supabase CLI](https://supabase.com/docs/guides/local-development/cli/getting-started)

### Instalar self hosted supabase
Si ya tienes cualquiera de los dos, **actualizalos para evitar errores**.

```
Si usas docker desktop en Windows, esta es la configuración que deberías tener.
<img src="https://supabase.com/docs/_next/image?url=%2Fdocs%2Fimg%2Fguides%2Fcli%2Fdocker-win.png&w=3840&q=75&dpl=dpl_EU6MXvnLKJuwyo4VfbBx9GiJt9Qx" style="margin: 10px 0px; width: 55rem;">

### Iniciar supabase en local

Entramos en la carpeta del repositorio

```bash
cd ${DIRECTORIO_DE_EMERGENCY_CV}
supabase login
supabase init
supabase link --project-ref nmvcsenkfqbdlfdtiqdo
```

Iniciamos la base de datos (**tener docker encendido**)

```bash
supabase start
```

### Para hacer cambios en el schema
Si no vemos las tablas ni los datos de ejemplo cargados podemos refrescar la base de datos con:

```bash
supabase db reset
```

### Hacer cambios en el schema

- Editar como queremos que sea en local (studio de supabase)
- Ejecutar el comando:
#### Crear migracion automatica

Nos interesa usar esta opción, cuando queremos **editar la base de datos desde el studio web**

Cuando acabemos de realizar los cambios en el studio web, ejecutaremos el siguiente comando para generar la migration.

```bash
supabase db diff -f nombre_migracion
```
// nombre de la migracion es indicativo, no tiene nigun efecto
supabase db diff -f ${NOMBRE_DE_LA_MIGRACION}

#### Crear migración manual

Nos interesa usar esta opción, cuando queremos **editar la base de datos con codigo SQL manual**.

Primero, creamos la el archivo migration con

```bash
supabase migration new nombre_migracion
```

Se creara un **nuevo fichero** con el nombre que hemos usado **en supabase/migrations**

En ese archivo añadiremos todo el código SQL que necesitemos

Si queremos visualizar nuestros cambios en local, podemos usar

```bash
supabase db reset
```

- Esto generara una migracion en el local, hay que añadir esto al PR y github actions lo pondra en produccion.
<br>
La migration que generemos, la añadiremos en el PR.
8 changes: 8 additions & 0 deletions next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ const nextConfig = {
experimental: {
serverActions: true,
},
images: {
remotePatterns: [
{
protocol: 'https',
hostname: 'lh3.googleusercontent.com',
},
],
},
};

export default nextConfig;
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NextResponse } from 'next/server';
import { NextRequest, NextResponse } from 'next/server';
import { createClient } from '@/lib/supabase/server';

export async function GET() {
Expand All @@ -16,7 +16,7 @@ export async function GET() {
return Response.json({ registeredPost });
}

export async function POST(request) {
export async function POST(request: NextRequest) {
try {
// Obtener los datos del formulario (multipart/form-data)
const formData = await request.formData();
Expand Down
File renamed without changes.
25 changes: 0 additions & 25 deletions src/app/auth/page.js

This file was deleted.

34 changes: 34 additions & 0 deletions src/app/auth/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
'use client';
import { Suspense, useEffect } from 'react';
import Login from '../../components/auth/Login';
import { useRouter, useSearchParams } from 'next/navigation';
import { authService } from '@/lib/service';

export default function AUthPage() {
return (
<Suspense>
<Auth />
</Suspense>
);
}

function Auth() {
const router = useRouter();
const searchParams = useSearchParams();
const redirect = searchParams.get('redirect') || '/';
useEffect(() => {
async function fetchSession() {
const { data: session } = await authService.getSessionUser();
if (session.user) {
router.push(redirect);
}
}
fetchSession();
});

return (
<section className="mx-6 lg:m-16">
<Login onSuccessCallback={() => router.push(redirect)} redirectUrl={redirect} />
</section>
);
}
39 changes: 0 additions & 39 deletions src/app/casos-activos/layout.js

This file was deleted.

41 changes: 41 additions & 0 deletions src/app/casos-activos/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { createClient } from '@/lib/supabase/server';
import TabNavigation from '@/components/TabNavigation';
import { PropsWithChildren } from 'react';
import { SupabaseClient } from '@supabase/supabase-js';
import { Database } from '@/types/database';
const getCount = async (supabase: SupabaseClient<Database>) => {
const { count: solicitaCount, error: solicitaError } = await supabase
.from('help_requests')
.select('id', { count: 'exact' })
.eq('type', 'necesita');

const { count: ofreceCount, error: ofreceError } = await supabase
.from('help_requests')
.select('id', { count: 'exact' })
.eq('type', 'ofrece');

if (solicitaError) {
throw new Error('Error fetching solicita:', solicitaError);
}
if (ofreceError) {
throw new Error('Error fetching ofrece:', ofreceError);
}

return {
solicitudes: solicitaCount || 0,
ofertas: ofreceCount || 0,
};
};

export default async function CasosActivosLayout({ children }: PropsWithChildren) {
const supabase = await createClient();
const count = await getCount(supabase);
return (
<>
<div className="space-y-6 mx-auto max-w-7xl px-4 sm:px-6">
<TabNavigation count={count} />
{children}
</div>
</>
);
}
22 changes: 16 additions & 6 deletions src/app/casos-activos/mapa/page.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
'use client';

import { useState, useEffect } from 'react';
import { useState, useEffect, Suspense } from 'react';
import { supabase } from '@/lib/supabase/client';
import SolicitudCard from '@/components/SolicitudCard';
import { useRouter, useSearchParams } from 'next/navigation';
import { tiposAyudaOptions } from '@/helpers/constants';
import Map, { PinMapa } from '@/components/map/map';
import PickupPoint from '@/components/PickupPoint';
import { useTowns } from '@/context/TownProvider';

export default function Mapa() {
const towns = useTowns();
export const dynamic = 'force-dynamic';

export default function MapaPage() {
return (
<Suspense>
<Mapa />
</Suspense>
);
}

function Mapa() {
const searchParams = useSearchParams();
const router = useRouter();

Expand Down Expand Up @@ -47,7 +55,7 @@ export default function Mapa() {
latitude: request.latitude ?? 0,
longitude: request.longitude ?? 0,
id: request.id,
popup: <SolicitudCard isHref={true} isEdit={false} towns={towns} caso={request} />,
popup: <SolicitudCard showLink={true} showEdit={false} caso={request} />,
};
}

Expand Down Expand Up @@ -75,6 +83,8 @@ export default function Mapa() {
query.eq('urgency', filtroData.urgencia);
}

query.neq('status', 'finished');

const { data, error } = await query.order('created_at', { ascending: false });

const pickupQuery = supabase.from('collection_points').select('*', { count: 'exact' });
Expand Down Expand Up @@ -107,7 +117,7 @@ export default function Mapa() {
}

fetchData();
}, [filtroData, towns]);
}, [filtroData]);

if (loading) {
return (
Expand Down
Loading

0 comments on commit 9be5a5f

Please sign in to comment.