diff --git a/src/graphql/queries.ts b/src/graphql/queries.ts
deleted file mode 100644
index 07c534a8..00000000
--- a/src/graphql/queries.ts
+++ /dev/null
@@ -1,62 +0,0 @@
-import { gql } from '@apollo/client'
-
-const GET_COLLEGES = gql`
- query Colleges {
- colleges {
- collegeId
- name
- score
- city
- country
- programs {
- name
- courses {
- name
- degrees
- }
- }
- tuitionFee
- }
- }
-`
-
-const GET_COLLEGE = gql`
- query College($id: ID!) {
- college(id: $id) {
- collegeId
- name
- score
- city
- country
- programs {
- name
- courses {
- name
- degrees
- }
- }
- tuitionFee
- }
- }
-`
-
-const GET_TEST_COLLEGES = gql`
- query testColleges($limit: Int = 20, $seed: Float = 0) {
- testColleges(limit: $limit) {
- collegeId
- name
- score
- city
- country
- programs {
- name
- courses {
- name
- degrees
- }
- }
- tuitionFee
- }
- }
-`
-export { GET_COLLEGES, GET_COLLEGE, GET_TEST_COLLEGES }
diff --git a/src/graphql/resolvers.ts b/src/graphql/resolvers.ts
deleted file mode 100644
index 40564790..00000000
--- a/src/graphql/resolvers.ts
+++ /dev/null
@@ -1,44 +0,0 @@
-const resolvers = {
- Query: {
- colleges: async (
- _: unknown,
- __: unknown,
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
- context: any
- ) => {
- try {
- return await context.dataSources.colleges.getAllColleges()
- } catch (error) {
- throw new Error('Failed to fetch colleges')
- }
- },
- college: async (
- _: unknown,
- args: { collegeId: string },
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
- context: any
- ) => {
- try {
- return await context.dataSources.colleges.getCollegeById(args.collegeId)
- } catch (error) {
- console.log(error)
-
- throw new Error(`Failed to fetch college with id: ${args.collegeId} `)
- }
- },
- testColleges: async (
- _: unknown,
- args: { limit: number; seed: number },
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
- context: any
- ) => {
- try {
- return await context.dataSources.colleges.getTestColleges(args.limit, args.seed)
- } catch (error) {
- throw new Error('Failed to fetch test colleges')
- }
- },
- },
-}
-
-export default resolvers
diff --git a/src/graphql/schema.ts b/src/graphql/schema.ts
deleted file mode 100644
index 2342ecc7..00000000
--- a/src/graphql/schema.ts
+++ /dev/null
@@ -1,29 +0,0 @@
-const typeDefs = `#graphql
- type Query {
- college(collegeId: String!): College
- colleges: [College]
- testColleges(limit: Int = 20, seed: Float = 0): [College]
- }
-
- type College {
- collegeId: String!
- name: String!
- score: String!
- city: String!
- country: String!
- programs: [Program]
- tuitionFee: String
- }
-
- type Program {
- name: String!
- courses: [Course]
- }
-
- type Course {
- name: String!
- degrees: [String!]
- }
-`
-
-export default typeDefs
diff --git a/src/hooks/useDebounce.ts b/src/hooks/useDebounce.ts
new file mode 100644
index 00000000..01d41963
--- /dev/null
+++ b/src/hooks/useDebounce.ts
@@ -0,0 +1,19 @@
+import { useEffect, useState } from 'react'
+
+function useDebounce(value: string, delay: number) {
+ const [debouncedValue, setDebouncedValue] = useState(value)
+
+ useEffect(() => {
+ const handler = setTimeout(() => {
+ setDebouncedValue(value)
+ }, delay)
+
+ return () => {
+ clearTimeout(handler)
+ }
+ }, [value, delay])
+
+ return debouncedValue
+}
+
+export default useDebounce
diff --git a/src/lib/apollo-provider.tsx b/src/lib/apollo-provider.tsx
deleted file mode 100644
index b982b7ad..00000000
--- a/src/lib/apollo-provider.tsx
+++ /dev/null
@@ -1,27 +0,0 @@
-'use client'
-
-import { ApolloLink, HttpLink } from '@apollo/client'
-import { ApolloNextAppProvider, NextSSRInMemoryCache, NextSSRApolloClient, SSRMultipartLink } from '@apollo/experimental-nextjs-app-support/ssr'
-
-function makeClient() {
- const httpLink = new HttpLink({
- uri: '/api/graphql',
- })
-
- return new NextSSRApolloClient({
- cache: new NextSSRInMemoryCache(),
- link:
- typeof window === 'undefined'
- ? ApolloLink.from([
- new SSRMultipartLink({
- stripDefer: true,
- }),
- httpLink,
- ])
- : httpLink,
- })
-}
-
-export function ApolloWrapper({ children }: React.PropsWithChildren) {
- return
{children}
-}
diff --git a/src/lib/client.tsx b/src/lib/client.tsx
deleted file mode 100644
index d103f5b4..00000000
--- a/src/lib/client.tsx
+++ /dev/null
@@ -1,12 +0,0 @@
-import { HttpLink } from '@apollo/client'
-import { NextSSRInMemoryCache, NextSSRApolloClient } from '@apollo/experimental-nextjs-app-support/ssr'
-import { registerApolloClient } from '@apollo/experimental-nextjs-app-support/rsc'
-
-export const { getClient } = registerApolloClient(() => {
- return new NextSSRApolloClient({
- cache: new NextSSRInMemoryCache(),
- link: new HttpLink({
- uri: 'api/graphql',
- }),
- })
-})
diff --git a/src/models/common/api-client.ts b/src/models/common/api-client.ts
new file mode 100644
index 00000000..c8972980
--- /dev/null
+++ b/src/models/common/api-client.ts
@@ -0,0 +1,39 @@
+export type MethodType = 'GET' | 'POST' | 'PUT' | 'DELETE'
+
+export interface RequestData
{
+ data?: T | T[]
+ token?: string
+ headers?: { [key: string]: string }
+ absoluteUrl?: boolean
+ method?: MethodType
+ transform?: boolean
+ customBaseUrl?: boolean
+ id?: string | number
+ // categoryId?: string
+ // centerId?: string
+ // start_date?: string
+ // end_date?: string
+ // include_no_show_cancel?: boolean
+ page?: number
+ size?: number
+ userCode?: string
+ email?: string
+}
+
+export interface ServerData {
+ items: T[]
+}
+
+export interface SuccessResponse {
+ success: true
+}
+
+export type ServerResponse = T & T[] & ServerData & SuccessResponse
+
+export type RequestFields = string[]
+export interface IFieldsAndFilters {
+ fields?: RequestFields
+ filters?: T & { sortField?: string; sortOrder?: string }
+ offset?: number
+ limit?: number
+}
diff --git a/src/models/react-query.ts b/src/models/react-query.ts
new file mode 100644
index 00000000..693fc686
--- /dev/null
+++ b/src/models/react-query.ts
@@ -0,0 +1,4 @@
+import { UseQueryResult } from '@tanstack/react-query'
+import { AxiosError } from 'axios'
+
+export type QueryResponse = UseQueryResult
diff --git a/src/models/university.ts b/src/models/university.ts
new file mode 100644
index 00000000..deeb9e3b
--- /dev/null
+++ b/src/models/university.ts
@@ -0,0 +1,3 @@
+export interface universitySearchResponce {
+ result: []
+}
diff --git a/src/queries/queries.ts b/src/queries/queries.ts
deleted file mode 100644
index d524496c..00000000
--- a/src/queries/queries.ts
+++ /dev/null
@@ -1,12 +0,0 @@
-import { gql } from '@apollo/client'
-export const query = gql`
- query getUniversityList {
- universityList {
- id
- name
- score
- country
- city
- }
- }
-`
diff --git a/src/services/api-Client.ts b/src/services/api-Client.ts
new file mode 100644
index 00000000..01787eae
--- /dev/null
+++ b/src/services/api-Client.ts
@@ -0,0 +1,70 @@
+/* eslint-disable import/no-unresolved */
+import axios, { AxiosRequestConfig, AxiosResponse } from 'axios'
+
+import { RequestData, ServerResponse } from '../models/common/api-client'
+
+/**
+ * Handle Network Requests.
+ * @param {string} endpoint - Api path.
+ * @param {object} [config={}] - Config object.
+ * @param {string} config.method - Method.
+ * @param {object} config.data - Body for POST calls.
+ * @param {string} config.token - Token for authenticated calls.
+ * @param {object} config.headers - Additional headers
+ */
+
+const client = async (
+ endpoint: string,
+ {
+ id,
+
+ page,
+ size,
+ data,
+ headers,
+ method,
+ transform = true,
+ customBaseUrl = false,
+ userCode,
+ email,
+ ...rest
+ }: RequestData = {}
+): Promise> => {
+ const config: AxiosRequestConfig = {
+ url: customBaseUrl ? `${process.env.NEXT_PUBLIC_CUSTOM_BASE_URL}/${endpoint}` : `${process.env.NEXT_PUBLIC_API_BASE_URL}/${endpoint}`,
+ method: method || (data ? 'POST' : 'GET'),
+ data: data ? JSON.stringify(data) : undefined,
+ headers: { ...headers, 'Content-Type': 'application/json' },
+ params: {
+ id,
+
+ page,
+ size,
+ userCode,
+ email,
+ },
+ transformResponse: [].concat(
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
+ // @ts-ignore
+ axios.defaults.transformResponse,
+ (resp: ServerResponse) => {
+ if (transform && resp.items) {
+ return resp.items
+ }
+ return resp
+ }
+ ),
+ ...rest,
+ }
+
+ try {
+ const response: AxiosResponse> = await axios(config)
+ const { data: resData } = response
+
+ return resData
+ } catch (err) {
+ return Promise.reject(err)
+ }
+}
+
+export { client }
diff --git a/src/services/universitySearch.tsx b/src/services/universitySearch.tsx
new file mode 100644
index 00000000..1d652607
--- /dev/null
+++ b/src/services/universitySearch.tsx
@@ -0,0 +1,33 @@
+import useDebounce from '@/hooks/useDebounce'
+import { useQuery } from '@tanstack/react-query'
+import { client } from './api-Client'
+import { ServerResponse } from '@/models/common/api-client'
+
+interface UniversitySearchResult {
+ isLoading: boolean
+ data: ServerResponse | []
+}
+
+export function useUniversitySearch(searchTerm: string): UniversitySearchResult {
+ // Debounce the search term with a 1-second delay
+ const debouncedSearchTerm = useDebounce(searchTerm, 1000)
+ // console.log(searchTerm)
+
+ // console.log(debouncedSearchTerm)
+
+ const { isLoading, data } = useQuery({
+ enabled: Boolean(debouncedSearchTerm),
+ queryKey: ['searchTerm', debouncedSearchTerm],
+ queryFn: () => getUniversitySearch(debouncedSearchTerm),
+ })
+
+ return { isLoading, data }
+}
+
+export async function getUniversitySearch(searchTerm: string) {
+ // const [_, debouncedSearchTerm] = queryKey
+ // console.log('deb', debouncedSearchTerm)
+
+ const response = await client(`university/searched?searchTerm=${searchTerm}`)
+ return response
+}
diff --git a/src/stories/Home.stories.tsx b/src/stories/Home.stories.tsx
deleted file mode 100644
index d666c554..00000000
--- a/src/stories/Home.stories.tsx
+++ /dev/null
@@ -1,33 +0,0 @@
-import Home from '../app/page'
-import { GET_COLLEGES } from '@/graphql/queries'
-import { ApolloWrapper } from '@/lib/apollo-provider'
-const story = {
- title: 'HomePage',
- component: Home,
- parameters: {
- layout: 'fullscreen',
- apolloClient: {
- // do not put MockedProvider here, you can, but its preferred to do it in preview.js
- mocks: [
- {
- request: {
- query: GET_COLLEGES,
- },
- result: {
- data: {
- viewer: null,
- },
- },
- },
- ],
- },
- },
-}
-
-export default story
-const Template = () => (
-
-
-
-)
-export const homePage = Template.bind({})
diff --git a/src/utils/Provider.tsx b/src/utils/Provider.tsx
new file mode 100644
index 00000000..ffe19a65
--- /dev/null
+++ b/src/utils/Provider.tsx
@@ -0,0 +1,22 @@
+'use client'
+import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
+import { useState, ReactNode } from 'react'
+
+interface ReactQueryClientProviderProps {
+ children: ReactNode
+}
+
+export const ReactQueryClientProvider = ({ children }: ReactQueryClientProviderProps) => {
+ const [queryClient] = useState(
+ () =>
+ new QueryClient({
+ defaultOptions: {
+ queries: {
+ refetchOnWindowFocus: false,
+ },
+ },
+ })
+ )
+
+ return {children}
+}