From 8c1adfc413a9e31b860f57de1c79f6e23d18d51b Mon Sep 17 00:00:00 2001 From: Jaya Date: Sat, 29 Jul 2023 14:30:28 +0530 Subject: [PATCH] resolved conflicts in CreateGoals --- .../SettingGoals/CreateGoals.tsx | 83 ++++++------------- .../ToDoComponent/SettingGoals/POST_API.tsx | 34 ++++++++ .../DeadLineDatePicker.tsx | 2 +- 3 files changed, 62 insertions(+), 57 deletions(-) create mode 100644 src/components/ToDoComponent/SettingGoals/POST_API.tsx diff --git a/src/components/ToDoComponent/SettingGoals/CreateGoals.tsx b/src/components/ToDoComponent/SettingGoals/CreateGoals.tsx index dbb3ac85..92b1d716 100644 --- a/src/components/ToDoComponent/SettingGoals/CreateGoals.tsx +++ b/src/components/ToDoComponent/SettingGoals/CreateGoals.tsx @@ -8,68 +8,24 @@ import { StyleSheet, TouchableOpacity, } from 'react-native'; -import DurationDropDown from './SettingGoalsComponents/DurationDropDown'; -import DeadLineDatePicker, { deadlineDate } from './SettingGoalsComponents/DeadLineDatePicker'; +import DeadLineDatePicker from './SettingGoalsComponents/DeadLineDatePicker'; +import postData from './POST_API'; +export let selectedMemberData: string, + titleData: string, + descriptionData: string; const MainScreen = ({ navigation }) => { const [selectedMember, setSelectedMember] = React.useState(''); const [titleText, setTitleText] = useState(''); const [descriptionText, setDescriptionText] = useState(''); - - const postData = async () => { - const url = 'https://backend-goals-production.up.railway.app/goal/'; - let request = await fetch(url, { - method: 'POST', - headers: { - 'Content-type': 'application/json', - }, - body: JSON.stringify({ - data: [ - { - type: 'Goal', - id: '1', - attributes: { - title: titleText, - description: descriptionText, - created_at: '2023-06-22T00:08:38.695783Z', - created_by: '', - assigned_to: selectedMember, - starts_on: null, - ends_on: deadlineDate, - percentage_completed: 20, - assigned_by: '', - status: 'COMPLETED', - }, - }, - ], - }), - }); - }; + selectedMemberData = selectedMember; + titleData = titleText; + descriptionData = descriptionText; return ( - - - Add New Goal - + + Add New Goal Title { onChangeText={setTitleText} placeholder="Enter title max of 50 characters." /> - Description + Description { + const url = 'https://backend-goals-production.up.railway.app/goal/'; + let request = await fetch(url, { + method: 'POST', + headers: { + 'Content-type': 'application/vnd.api+json', + }, + body: JSON.stringify({ + data: { + type: 'Goal', + id: '', + attributes: { + title: titleData, + description: descriptionData, + assigned_to: selectedMemberData, + ends_on: deadlineDate, + }, + }, + }), + }); + request = await request.json(); + if (request.ok) { + Alert.alert(`Successfully created the goal.`); + } else { + Alert.alert(`${request.status}`); + } +}; + +export default postData; diff --git a/src/components/ToDoComponent/SettingGoals/SettingGoalsComponents/DeadLineDatePicker.tsx b/src/components/ToDoComponent/SettingGoals/SettingGoalsComponents/DeadLineDatePicker.tsx index f4b8f27f..6cb8cb17 100644 --- a/src/components/ToDoComponent/SettingGoals/SettingGoalsComponents/DeadLineDatePicker.tsx +++ b/src/components/ToDoComponent/SettingGoals/SettingGoalsComponents/DeadLineDatePicker.tsx @@ -2,7 +2,7 @@ import React, { useState } from 'react'; import { Text, TouchableOpacity, StyleSheet, ScrollView } from 'react-native'; import DatePicker from 'react-native-date-picker'; -export let deadlineDate; +export let deadlineDate: Date; const DeadLineDatePicker = () => { const [date, setDate] = useState(new Date()); const [open, setOpen] = useState(false);