diff --git a/app/(tabs)/agenda/agendaView.tsx b/app/(tabs)/agenda/agendaView.tsx index 546e3b5..bc044e7 100644 --- a/app/(tabs)/agenda/agendaView.tsx +++ b/app/(tabs)/agenda/agendaView.tsx @@ -89,7 +89,7 @@ export default function ViewAgenda({ data, handleClose }: Props) { item.id} - renderItem={({ item }) => } + renderItem={({ item }) => } /> diff --git a/app/(tabs)/agenda/index.tsx b/app/(tabs)/agenda/index.tsx index 4facabb..84e1a91 100644 --- a/app/(tabs)/agenda/index.tsx +++ b/app/(tabs)/agenda/index.tsx @@ -40,7 +40,7 @@ export default function Agenda() { const url = `${process.env.EXPO_PUBLIC_API_URL}/getAllAgendasLinkedToUser?uid_do_responsavel=${userUid}&api_key=${process.env.EXPO_PUBLIC_API_KEY}`; console.log("Fetching agendas for UID:", userUid); - + setLoading(true); // Start loading return fetch(url) diff --git a/components/addTaskToAgenda.tsx b/components/addTaskToAgenda.tsx index 5a128d3..fbfbc7f 100644 --- a/components/addTaskToAgenda.tsx +++ b/components/addTaskToAgenda.tsx @@ -114,6 +114,7 @@ const styles = StyleSheet.create({ paddingRight: 15, borderWidth: 1, borderColor: "rgba(96, 39, 170, 0.6)", + backgroundColor: '#FFF', borderRadius: 4 }, titleInput: { diff --git a/components/deletePublicTask.tsx b/components/deletePublicTask.tsx new file mode 100644 index 0000000..84cab3f --- /dev/null +++ b/components/deletePublicTask.tsx @@ -0,0 +1,103 @@ +import { View, Text, StyleSheet, TouchableOpacity } from 'react-native'; +import { useState, useEffect } from 'react'; +import { Ionicons } from '@expo/vector-icons'; +import { FAB } from 'react-native-paper'; + +type Task = { + id: string; + nome_da_tarefa: string; + timestamp: string; +}; + +type Props={ + data: Task; + handleClose: ()=> void + finalRemove: ()=> void +} + +export function DelPublicTask({data, handleClose, finalRemove}:Props){ + + return ( + + + + + + + Deseja realmente deletar: + {data.nome_da_tarefa}? + + + + + + ) +} + +const styles = StyleSheet.create({ + container: { + padding: "3%", + backgroundColor: "rgba(93, 93, 93, 0.5)", + flex: 1, + justifyContent: "center", + alignItems: "center" + }, + + text: { + width: "100%", + alignItems: "center", + }, + nameTask: { + fontSize: 23, + marginVertical: 15, + fontWeight: 'bold' + }, + + close: { + position: "absolute", + top: -20, + left: -5 + }, + + content: { + justifyContent: "center", + alignItems: "center", + width: "90%", + padding: 15, + backgroundColor: "#FFF", + borderRadius: 8, + paddingBottom: 30, + paddingTop: 30, + }, + textInput: { + borderWidth: 1, + borderColor: "purple", + marginTop: 15, + borderRadius: 8, + width: "100%", + padding: 10 + }, + button: { + color: '#FFF', + backgroundColor: "#b686f4", + height: 50, + width: 150, + borderRadius: 6, + justifyContent: "center", + alignItems: "center" + }, + + btnText: { + color: "#FFF", + fontSize: 17, + fontWeight: "bold" + }, + label: { + fontSize: 17 + } +}) \ No newline at end of file diff --git a/components/publicAgendaItem.tsx b/components/publicAgendaItem.tsx index dee523a..a391705 100644 --- a/components/publicAgendaItem.tsx +++ b/components/publicAgendaItem.tsx @@ -2,8 +2,7 @@ import { Ionicons } from "@expo/vector-icons"; import { useState } from "react"; import { Modal, StyleSheet, Text, TouchableOpacity, View } from "react-native"; import { useTheme } from "react-native-paper"; -import TaskInfo from './cardInfo'; -import TaskDel from "./cardDel"; +import { DelPublicTask } from "./deletePublicTask"; type Task = { id: string; @@ -11,22 +10,57 @@ type Task = { timestamp: string; }; +type Agenda = { + id: string + uid_da_agenda: string + nome_agenda: string + chave_de_convite: string + firstCreated: string +}; + type Props = { data: Task; + agendaData: { + id: string + uid_da_agenda: string + nome_agenda: string; + chave_de_convite: string; + firstCreated: string; + } }; -export function PublicTaskItem({data}:Props) { - const [infoView, setInfoView] = useState(false); +export function PublicTaskItem({ agendaData, data }: Props) { const [delView, setDelView] = useState(false); - const { colors } = useTheme(); + const chave = encodeURIComponent(process.env.EXPO_PUBLIC_API_KEY ?? ''); + + const deletarTask = async () => { + try { + const url = `${process.env.EXPO_PUBLIC_API_URL}/delete/agenda/tarefa?uid_da_agenda=${agendaData.uid_da_agenda}&uid_da_tarefa=${data.id}&api_key=${chave}` + const response = await fetch(url, { + method: 'DELETE', + }); + if (!response.ok) { + const text = await response.text(); + console.log(`${response.status} - ${text}`); + } + console.log('tarefa deletada!'); + } catch (err) { + console.log('erro ao deletar a tarefa: ', err) + } + } + + const setDeleteAndClose = async () => { + await deletarTask(); + console.log('operação finalizada'); + setDelView(false); + } console.log(`Data do componente publicAgendaItem: ${JSON.stringify(data)}`) return ( setInfoView(true)} activeOpacity={0.85} style={[ styles.card, @@ -56,6 +90,10 @@ export function PublicTaskItem({data}:Props) { color={colors.onPrimary} /> + + + setDelView(false)} /> +