diff --git a/components/Card/StudyGroup/index.js b/components/Card/StudyGroup/index.js index 705c5283..fa98eb1b 100644 --- a/components/Card/StudyGroup/index.js +++ b/components/Card/StudyGroup/index.js @@ -7,6 +7,8 @@ import { useTranslation } from 'react-i18next' import RenderField from '../../RenderField' export function StudyGroupCard({ studyGroup }) { + if (!studyGroup.active) return null + const [showMore, setShowMore] = useState(false) const { t } = useTranslation() @@ -88,6 +90,3 @@ export function StudyGroupCard({ studyGroup }) { ) } - - - \ No newline at end of file diff --git a/firebase.json b/firebase.json index 358bd433..d3d42763 100644 --- a/firebase.json +++ b/firebase.json @@ -17,10 +17,16 @@ }, "auth": { "enabled": true + }, + "storage": { + "port": 9199 } }, "firestore": { "rules": "firestore.rules", "indexes": "firestore.indexes.json" + }, + "storage": { + "rules": "storage.rules" } } diff --git a/next.config.js b/next.config.js index c0a49133..40444d6f 100644 --- a/next.config.js +++ b/next.config.js @@ -5,6 +5,11 @@ module.exports = { localeDetection: true, // Turn off automatic locale detection }, images: { - domains: ['assets.zipschool.com', 'cdn.buildspace.so', 'firebasestorage.googleapis.com'], + domains: [ + 'assets.zipschool.com', + 'cdn.buildspace.so', + 'firebasestorage.googleapis.com', + 'localhost', + ], }, } diff --git a/pages/admin/createGroup.js b/pages/admin/createGroup.js index 68033f40..73018ca1 100644 --- a/pages/admin/createGroup.js +++ b/pages/admin/createGroup.js @@ -2,23 +2,27 @@ import React, { useState } from 'react' import { withProtected } from '../../hooks/route' import { useRouter } from 'next/router' import { db, storage } from '../../firebase/initFirebase' -import { collection, addDoc } from 'firebase/firestore' +import { collection, addDoc, Timestamp } from 'firebase/firestore' import { useTranslation } from 'react-i18next' import Head from 'next/head' import { ref, uploadBytes, getDownloadURL } from 'firebase/storage' function CreateStudyGroup({ user }) { const [formData, setFormData] = useState({ - title: '', - description: '', - difficulty: 'Beginner', - language: 'pt', - scheduled_at: '', + language: '', leader_discord_id: '', + scheduled_at: '', image_url: '', + difficulty: 'beginner', active: true, index: 0, }) + + const [tempLanguageData, setTempLanguageData] = useState({ + title: '', + description: '', + }) + const router = useRouter() const { t } = useTranslation() @@ -35,6 +39,11 @@ function CreateStudyGroup({ user }) { })) }) }) + } else if (name === 'title' || name === 'description') { + setTempLanguageData((prevData) => ({ + ...prevData, + [name]: value, + })) } else { setFormData((prevData) => ({ ...prevData, @@ -44,18 +53,42 @@ function CreateStudyGroup({ user }) { } const handleSubmit = async (e) => { - e.preventDefault() - const slug = formData.title.toLowerCase().replace(/ /g, '-') + e.preventDefault() // Garante que isso seja chamado primeiro + + if (!formData.language) { + alert(t('pleaseSelectLanguage')) + return + } + + if (!formData.image_url) { + alert(t('pleaseWaitForImageUpload')) + return + } + + const slug = tempLanguageData.title.toLowerCase().replace(/ /g, '-') + try { - const docRef = await addDoc(collection(db, 'study_groups'), { + const finalFormData = { ...formData, - scheduled_at: new Date(formData.scheduled_at), + scheduled_at: Timestamp.fromDate(new Date(formData.scheduled_at)), slug: slug, - }) + index: parseInt(formData.index, 10), + title: tempLanguageData.title, + description: tempLanguageData.description, + metadata: { + [formData.language]: { + title: tempLanguageData.title, + description: tempLanguageData.description, + }, + }, + } + const docRef = await addDoc(collection(db, 'study_groups'), finalFormData) console.log('Study group added with ID: ', docRef.id) + alert(t('studyGroupCreatedSuccessfully')) // Adiciona feedback de sucesso router.push(`/study-groups/${slug}`) } catch (error) { console.error('Error adding study group: ', error) + alert(t('errorCreatingStudyGroup')) // Adiciona feedback de erro } } @@ -67,6 +100,24 @@ function CreateStudyGroup({ user }) {

{t('createStudyGroup')}

+
+ + +