Skip to content

Commit

Permalink
refactor(frontend): added projects to context api init values and upd…
Browse files Browse the repository at this point in the history
…ated project type to add org name and id
  • Loading branch information
bekossy committed Dec 6, 2024
1 parent 09d2def commit f1c26ad
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
6 changes: 6 additions & 0 deletions agenta-web/src/contexts/project.context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const DEFAULT_UUID = "00000000-0000-0000-0000-000000000000"

type ProjectContextType = {
project: ProjectsResponse | null
projects: ProjectsResponse[]
isProjectId: boolean
projectId: string
isLoading: boolean
Expand All @@ -19,6 +20,7 @@ type ProjectContextType = {

const initialValues: ProjectContextType = {
project: null,
projects: [],
isProjectId: false,
projectId: "",
isLoading: false,
Expand All @@ -36,6 +38,7 @@ export const getCurrentProject = () => projectContextValues

const ProjectContextProvider: React.FC<PropsWithChildren> = ({children}) => {
const [project, setProject] = useStateCallback<ProjectsResponse | null>(null)
const [projects, setProjects] = useState<ProjectsResponse[]>([])
const [useOrgData, setUseOrgData] = useState<Function>(() => () => "")
const [isLoading, setIsLoading] = useState(false)
const {doesSessionExist} = useSession()
Expand Down Expand Up @@ -63,6 +66,7 @@ const ProjectContextProvider: React.FC<PropsWithChildren> = ({children}) => {
: data[0] || null

setProject(_project, onSuccess)
setProjects(data)
} catch (error) {
console.error(error)
setProject(null)
Expand All @@ -82,6 +86,7 @@ const ProjectContextProvider: React.FC<PropsWithChildren> = ({children}) => {
}

projectContextValues.project = project
projectContextValues.projects = projects
projectContextValues.isLoading = isLoading
projectContextValues.isProjectId = isProjectId
projectContextValues.projectId = projectId
Expand All @@ -90,6 +95,7 @@ const ProjectContextProvider: React.FC<PropsWithChildren> = ({children}) => {
<ProjectContext.Provider
value={{
project,
projects,
isProjectId,
projectId,
isLoading,
Expand Down
2 changes: 2 additions & 0 deletions agenta-web/src/services/project/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ export interface ProjectsResponse {
project_name: string
user_role?: string | null
is_demo?: boolean | null
organization_id?: string | null
organization_name?: string | null
}

0 comments on commit f1c26ad

Please sign in to comment.