diff --git a/client-new/src/screens/app/SubTaskScreen.tsx b/client-new/src/screens/app/SubTaskScreen.tsx index ad2c4a2..293f8ed 100644 --- a/client-new/src/screens/app/SubTaskScreen.tsx +++ b/client-new/src/screens/app/SubTaskScreen.tsx @@ -1,21 +1,21 @@ import { IAction, IActionList } from '@/interfaces/IAction'; import { getActions } from '@/services/SubTaskService'; -import { ENDPOINT } from '@/services/const'; +import { API_BASE_URL } from '@/services/const'; import FormComponent from '@/utils/Actions'; import { Text } from 'native-base'; import { useEffect, useState } from 'react'; import React from 'react'; -import { useQuery } from 'react-query'; +import { useQuery } from '@tanstack/react-query'; const SubTaskScreen = ({ subtask_id }) => { const [state, setState] = useState(null); // props should include a id field - const { isLoading, error, data } = useQuery( - ['fetchActions', subtask_id], - () => getActions(subtask_id) - ); + const { isLoading, error, data } = useQuery({ + queryKey: ['actions', subtask_id], + queryFn: () => getActions(subtask_id) + }); console.log('action fetched: ', data); // {"actions": [{"action_type": "input", "label": "Full Legal Name", "name": "full_name", "placeholder": "Enter your full legal name", "required": true, "type": "text"}, {"action_type": "input", "description": "Please enter your date of birth in the format: MM/DD/YYYY", "label": "Date of Birth", "name": "date_of_birth", "placeholder": "MM/DD/YYYY", "required": true, "type": "date"}, {"action_type": "input", "description": "Please provide your 9-digit social security number", "label": "Social Security Number", "name": "ssn", "placeholder": "Enter your social security number", "required": true, "type": "text"}, {"action_type": "input", "description": "Please provide your complete current residential address", "label": "Current Address", "name": "current_address", "placeholder": "Enter your current address", "required": true, "type": "text"}, {"action_type": "input", "description": "Please provide a valid phone number where you can be reached", "label": "Phone Number", "name": "phone_number", "placeholder": "Enter your phone number", "required": true, "type": "tel"}, {"action_type": "input", "description": "Please provide a valid email address for communication purposes", "label": "Email Address", "name": "email", "placeholder": "Enter your email address", "required": true, "type": "email"}, {"action_type": "select", "description": "Please select your current marital status from the options provided", "label": "Marital Status", "name": "marital_status", "options": [Array], "placeholder": "Select your marital status", "required": true}, {"action_type": "textarea", "description": "Feel free to provide any additional information or comments here", "label": "Additional Comments", "name": "additional_comments", "placeholder": "Enter any additional comments", "required": false}, {"action_type": "checkbox", "description": "Select the services you require", "label": "Select Services", "name": "services", "options": [Array], "required": true}, {"action_type": "radio", "description": "Select your preferred method of payment", "label": "Select Payment Method", "name": "payment_method", "options": [Array], "required": true}]} diff --git a/client-new/src/services/FileService.ts b/client-new/src/services/FileService.ts index 634124b..3cac251 100644 --- a/client-new/src/services/FileService.ts +++ b/client-new/src/services/FileService.ts @@ -1,19 +1,9 @@ import { IFile } from '@/interfaces/IFile'; import axios from 'axios'; +import { API_BASE_URL } from '@/services/const'; -import { ENDPOINT } from './const'; - -export const getUserFilesList = (userId: number): Promise => { - return new Promise((resolve, reject) => { - setTimeout(() => { - axios - .get(`${ENDPOINT}/api/files/${userId}/user`) - .then((res) => { - resolve(res.data); - }) - .catch((error) => { - reject(error.response.data); - }); - }); - }); -}; +export const getUserFilesList = async (userId: number): Promise => { + const response = await axios.get(`${API_BASE_URL}/files/${userId}/user`); + return response.data; + // return response.status === 200 ? response.data : []; +}; \ No newline at end of file diff --git a/client-new/src/services/GuideService.ts b/client-new/src/services/GuideService.ts index b5e4bbb..e4b1fe1 100644 --- a/client-new/src/services/GuideService.ts +++ b/client-new/src/services/GuideService.ts @@ -2,17 +2,16 @@ import axios from 'axios'; import { IGuide } from '@/interfaces/IGuide'; import { sleep } from '@/utils/MockDelayUtil'; - -const API_BASE_URL = 'http://localhost:8080/api'; +import { API_BASE_URL } from '@/services/const'; export const fetchAllGuides = async () => { - await sleep(1000) + await sleep(1000) // Simulate network delay const response = await axios.get(`${API_BASE_URL}/guides/`); return response.data as IGuide[]; } export const fetchGuideByName = async (name: string) => { - await sleep(10000) + await sleep(10000) // Simulate network delay const response = await axios.get(`${API_BASE_URL}/guides/${name}`); return response.data as IGuide; } diff --git a/client-new/src/services/PersonaService.ts b/client-new/src/services/PersonaService.ts index 1cdf21e..e057ea1 100644 --- a/client-new/src/services/PersonaService.ts +++ b/client-new/src/services/PersonaService.ts @@ -2,11 +2,9 @@ import axios from 'axios'; import { IPersona } from '../interfaces/IPersona'; import { IUser } from '../interfaces/IUser'; +import { API_BASE_URL } from '@/services/const'; -export const fetchUserPersona = async (user_id: number) => { - const response = await axios.get( - `http://localhost:8080/api/users/${user_id}/persona` - ); - - return response.data as IPersona; +export const fetchUserPersona = async (user_id: number): Promise => { + const response = await axios.get(`${API_BASE_URL}/users/${user_id}/persona`); + return response.data; }; diff --git a/client-new/src/services/ProfileService.ts b/client-new/src/services/ProfileService.ts index 99614c4..0d9355b 100644 --- a/client-new/src/services/ProfileService.ts +++ b/client-new/src/services/ProfileService.ts @@ -2,8 +2,7 @@ import axios from 'axios'; import { IOnboardingFlowState } from '../interfaces/IOnboardingFlowState'; import { IProfile } from '../interfaces/IProfile'; - -const API_BASE_URL = 'http://localhost:8080/api'; +import { API_BASE_URL } from '@/services/const'; export const getProfile = async (user_id: string) => { const response = await axios.get(`${API_BASE_URL}/users/${user_id}/profile`); diff --git a/client-new/src/services/SubTaskService.ts b/client-new/src/services/SubTaskService.ts index acf5e08..367d263 100644 --- a/client-new/src/services/SubTaskService.ts +++ b/client-new/src/services/SubTaskService.ts @@ -1,7 +1,6 @@ import { IAction, IActionList } from '@/interfaces/IAction'; import axios from 'axios'; - -import { ENDPOINT } from './const'; +import { API_BASE_URL } from '@/services/const'; export const getActions = async (subtask_id: number) => { try { diff --git a/client-new/src/services/TaskService.ts b/client-new/src/services/TaskService.ts index a9dd550..5fe2345 100644 --- a/client-new/src/services/TaskService.ts +++ b/client-new/src/services/TaskService.ts @@ -1,7 +1,6 @@ import { ITask } from '@/interfaces/ITask'; import axios from 'axios'; - -const API_BASE_URL = 'http://localhost:8080/api'; +import { API_BASE_URL } from '@/services/const'; export const fetchAllUserTasks = async (userId: string) => { const response = await axios.get(`${API_BASE_URL}/tasks/${userId}/user`); diff --git a/client-new/src/services/UserService.ts b/client-new/src/services/UserService.ts index 8eaa6df..3a88f33 100644 --- a/client-new/src/services/UserService.ts +++ b/client-new/src/services/UserService.ts @@ -4,7 +4,7 @@ import { z } from 'zod'; import { IProfile } from '@/interfaces/IProfile'; import { IUser } from '@/interfaces/IUser'; -const API_BASE_URL = 'http://localhost:8080/api'; +import { API_BASE_URL } from '@/services/const'; export const fetchUser = async (firebaseID: string): Promise> => { const response = await axios.get(`${API_BASE_URL}/users/firebase/${firebaseID}`); diff --git a/client-new/src/services/const.ts b/client-new/src/services/const.ts index 48474d2..4553d0e 100644 --- a/client-new/src/services/const.ts +++ b/client-new/src/services/const.ts @@ -1 +1,5 @@ -export const ENDPOINT = 'https://legacy.loca.lt'; +/** + * API_BASE_URL is a constant that is used to determine the base URL for the API. + */ +export const API_BASE_URL = true ? 'http://localhost:8080/api' : 'https://legacy.loca.lt/api'; +