-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: removed company store; added graphql fetching
- Loading branch information
1 parent
7c28a4b
commit e48062a
Showing
7 changed files
with
97 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import React, { createContext, useContext } from "react"; | ||
import { type Company } from "@/types"; | ||
import { useQuery } from "@apollo/client"; | ||
import { getCompanies } from "@/lib/graphql/queries"; | ||
|
||
type CollectionContextType = { | ||
companies: Company[] | undefined; | ||
loading: boolean; | ||
refreshCompanies: () => Promise<void>; | ||
}; | ||
|
||
const CollectionContext = createContext<CollectionContextType | undefined>(undefined); | ||
|
||
export function CollectionProvider({ children }: { children: React.ReactNode }) { | ||
const { loading, data: companies = [], refetch } = useQuery(getCompanies, { pollInterval: 300000 }); | ||
|
||
const refreshCompanies = async () => { | ||
await refetch(); | ||
}; | ||
|
||
return ( | ||
<CollectionContext.Provider value={{ companies, loading, refreshCompanies }}>{children}</CollectionContext.Provider> | ||
); | ||
} | ||
|
||
export function useCollection() { | ||
const context = useContext(CollectionContext); | ||
if (context === undefined) { | ||
throw new Error("useCollection must be used within a CollectionProvider"); | ||
} | ||
return context; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,8 @@ | ||
import { createSlice, type PayloadAction } from "@reduxjs/toolkit"; | ||
import { type Appointment, type Company } from "@/types"; | ||
import { Role } from "@/types/role"; | ||
import { type Appointment } from "@/types"; | ||
|
||
type CollectionState = { | ||
appointments: Appointment[]; | ||
companies: Company[]; | ||
}; | ||
|
||
const initialState: CollectionState = { | ||
|
@@ -42,81 +40,6 @@ const initialState: CollectionState = { | |
client: null, | ||
status: "BOOKED" | ||
} | ||
], | ||
companies: [ | ||
{ | ||
id: "0", | ||
name: "GitHub", | ||
createdAt: new Date(2024, 8, 23).toDateString(), | ||
description: "GitHub is a web-based platform for version control and collaboration.", | ||
owner: { | ||
id: 124, | ||
name: "John Doe", | ||
email: "[email protected]", | ||
role: Role.COMPANY_ADMIN, | ||
companyID: "1" | ||
}, | ||
members: [], | ||
settings: { | ||
appointmentDuration: 60, | ||
appointmentBuffer: 15, | ||
appointmentTypes: [], | ||
appointmentLocations: [], | ||
openingHours: { | ||
from: "08:00", | ||
to: "18:00" | ||
} | ||
} | ||
}, | ||
{ | ||
id: "1", | ||
name: "Vercel", | ||
createdAt: new Date(2024, 8, 23).toDateString(), | ||
description: "Vercel is a cloud platform for static sites and Serverless Functions.", | ||
owner: { | ||
id: 123, | ||
name: "John Doe", | ||
email: "[email protected]", | ||
role: Role.COMPANY_ADMIN, | ||
companyID: "2" | ||
}, | ||
members: [], | ||
settings: { | ||
appointmentDuration: 60, | ||
appointmentBuffer: 15, | ||
appointmentTypes: [], | ||
appointmentLocations: [], | ||
openingHours: { | ||
from: "08:00", | ||
to: "18:00" | ||
} | ||
} | ||
}, | ||
{ | ||
id: "2", | ||
name: "Google", | ||
createdAt: new Date(2024, 8, 23).toDateString(), | ||
description: | ||
"Google is an American multinational technology company that specializes in Internet-related services and products.", | ||
owner: { | ||
id: 125, | ||
name: "John Doe", | ||
email: "[email protected]", | ||
role: Role.COMPANY_ADMIN, | ||
companyID: "3" | ||
}, | ||
members: [], | ||
settings: { | ||
appointmentDuration: 60, | ||
appointmentBuffer: 15, | ||
appointmentTypes: [], | ||
appointmentLocations: [], | ||
openingHours: { | ||
from: "08:00", | ||
to: "18:00" | ||
} | ||
} | ||
} | ||
] | ||
}; | ||
|
||
|
@@ -126,13 +49,10 @@ export const collectionSlice = createSlice({ | |
reducers: { | ||
setAppointments(state, action: PayloadAction<Appointment[]>) { | ||
state.appointments = action.payload; | ||
}, | ||
setCompanies(state, action: PayloadAction<Company[]>) { | ||
state.companies = action.payload; | ||
} | ||
} | ||
}); | ||
|
||
export const { setAppointments, setCompanies } = collectionSlice.actions; | ||
export const { setAppointments } = collectionSlice.actions; | ||
|
||
export default collectionSlice.reducer; |