Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
darkghost078 committed Nov 6, 2024
2 parents 2398e93 + f281fdb commit 8a78a4d
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 11 deletions.
16 changes: 15 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
48 changes: 41 additions & 7 deletions src/pages/call4paper/call4paper.tsx
Original file line number Diff line number Diff line change
@@ -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',
Expand Down Expand Up @@ -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; }
Expand All @@ -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 (
Expand Down Expand Up @@ -108,7 +142,7 @@ export default function Call4Paper() {
<input type="text" name="pronouns" placeholder="Pronombres" className={`${styles.inputForm}`} onChange={handleChange} value={formData.pronouns} />
<input type="text" name="nickname" placeholder="Nick/Alias" className={`${styles.inputForm}`} onChange={handleChange} value={formData.nickname} />
<textarea name="notes" placeholder="¿Algo que debamos tener en cuenta? (comida, intolerancias, etc.)" className={`${styles.inputFormArea}`} onChange={handleChange} value={formData.notes}></textarea>
<input type="file" name="photo" className={`${styles.inputForm}`} onChange={handleChange} value={formData.photo} />
<input type="file" name="photo" className={`${styles.inputForm}`} onChange={handleImageChange} />
<textarea name="experience" placeholder="Experiencia Previa en Actividades del Estilo" className={`${styles.inputFormArea}`} onChange={handleChange} value={formData.experience}></textarea>
<input type="text" name="socialMediaLinks" placeholder="Enlaces a RRSS" className={`${styles.inputForm}`} onChange={handleChange} value={formData.socialMediaLinks} />
<input type="text" name="residence" placeholder="Municipio de Residencia Habitual" className={`${styles.inputForm}`} onChange={handleChange} value={formData.residence} />
Expand Down
4 changes: 2 additions & 2 deletions src/supabase/server.tsx
Original file line number Diff line number Diff line change
@@ -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 ||" ");**/

0 comments on commit 8a78a4d

Please sign in to comment.