diff --git a/package-lock.json b/package-lock.json index 0b01b19..cb69bde 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,7 +16,8 @@ "react": "^18.3.1", "react-dom": "^18.3.1", "react-router-dom": "^6.27.0", - "style-components": "^0.1.0" + "style-components": "^0.1.0", + "uuid": "^11.0.2" }, "devDependencies": { "@eslint/js": "^9.11.1", @@ -3569,6 +3570,19 @@ "punycode": "^2.1.0" } }, + "node_modules/uuid": { + "version": "11.0.2", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-11.0.2.tgz", + "integrity": "sha512-14FfcOJmqdjbBPdDjFQyk/SdT4NySW4eM0zcG+HqbHP5jzuH56xO3J1DGhgs/cEMCfwYi3HQI1gnTO62iaG+tQ==", + "funding": [ + "https://github.com/sponsors/broofa", + "https://github.com/sponsors/ctavan" + ], + "license": "MIT", + "bin": { + "uuid": "dist/esm/bin/uuid" + } + }, "node_modules/vite": { "version": "5.4.8", "resolved": "https://registry.npmjs.org/vite/-/vite-5.4.8.tgz", diff --git a/package.json b/package.json index 33c75b2..82e0cf5 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,8 @@ "react": "^18.3.1", "react-dom": "^18.3.1", "react-router-dom": "^6.27.0", - "style-components": "^0.1.0" + "style-components": "^0.1.0", + "uuid": "^11.0.2" }, "devDependencies": { "@eslint/js": "^9.11.1", diff --git a/src/pages/call4paper/call4paper.tsx b/src/pages/call4paper/call4paper.tsx index 603926f..6463e5c 100644 --- a/src/pages/call4paper/call4paper.tsx +++ b/src/pages/call4paper/call4paper.tsx @@ -1,9 +1,13 @@ import { useState } from "react"; import Navbar from "../../components/Navbar/Navbar"; import styles from "./call4paper.module.css"; -import { supabase } from "../../supabase/server"; +//import { supabase } from "../../supabase/server"; +//import { v4 as uuidv4 } from 'uuid'; export default function Call4Paper() { + const [userId, setUserId] = useState(''); + const [imageFile, setImageFile] = useState(null); // State for the image file + const [formData, setFormData] = useState({ title: '', activityType: 'charla', @@ -34,7 +38,30 @@ export default function Call4Paper() { }); }; - const handleInsert = async (e: any) => { + const handleImageChange = (e: any) => { + setImageFile(e.target.files[0]); // Store file in state + }; + + const uploadImage = async () => { + if (!imageFile) return null; // Return if no image is selected +/** + const { data, error } = await supabase + .storage + .from('user-uploads') + .upload(userId + "/" + formData.firstName + formData.lastName + uuidv4(), imageFile); + + if (error) { + console.log("Error uploading image:", error); + return null; + } else { + console.log("Image uploaded successfully", data); + return data.path; // Return the path of the uploaded image + } + + **/ + }; + + const handleInsert = async (e:any) => { e.preventDefault(); if (!formData.title) { alert("Por favor, indique el titulo"); return; } @@ -46,17 +73,24 @@ export default function Call4Paper() { if (!formData.nickname) { alert("Por favor, rellena el nickname"); return; } if (!formData.residence) { alert("Por favor, indique su residencia"); return; } + // Upload image only when the form is submitted + const imagePath = await uploadImage(); + const updatedFormData = { + ...formData, + photo: imagePath || '', // Add image path if uploaded successfully + }; + + /** + const { data, error } = await supabase .from('call4paper') - .insert([formData]); + .insert([updatedFormData]); if (error) { console.log("Data not inserted correctly", error); } else { console.log("Data inserted correctly", data); - } - - + }**/ }; return ( @@ -108,7 +142,7 @@ export default function Call4Paper() { - + diff --git a/src/supabase/server.tsx b/src/supabase/server.tsx index 77387fb..25be4c7 100644 --- a/src/supabase/server.tsx +++ b/src/supabase/server.tsx @@ -1,3 +1,3 @@ -import { createClient } from "@supabase/supabase-js"; +/**import { createClient } from "@supabase/supabase-js"; -export const supabase = createClient("https://gtvwlxhwpngxrfmrqzar.supabase.co","eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Imd0dndseGh3cG5neHJmbXJxemFyIiwicm9sZSI6ImFub24iLCJpYXQiOjE3MjcyODEyMzYsImV4cCI6MjA0Mjg1NzIzNn0.4n7preawGleulQXLrMiAAQ5EK1qh4tI1C--Jy8gAG9c") +export const supabase = createClient(import.meta.env.VITE_SOME_KEY|| " ", import.meta.env.VITE_SUPABASE_ANON_KEY ||" ");**/