generated from hackforla/.github-hackforla-base-repo-template
-
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created Context for Qualifier 1 Page (#502)
* Refactored QualifiersPageRoles, added context, and updated documentataion on COP JSON structure * Removed copData fetching from QualifiersPageRoles and lifted copData to QualifiersContext * Cleaned up strings for JSON * Removed extra backtick in markdown
- Loading branch information
1 parent
fd766f0
commit 3aa6974
Showing
6 changed files
with
269 additions
and
79 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import React, { createContext, useContext, useState, ReactNode } from "react"; | ||
import { copData, copDatum } from "api_data/copData"; | ||
|
||
// Types | ||
type QualifiersType = { | ||
COPs: { | ||
[copName: string]: string[]; | ||
}; | ||
// availabilityTimeSlots: string[]; | ||
}; | ||
|
||
type QualifiersContextType = { | ||
copData: copDatum[]; | ||
qualifiers: QualifiersType; | ||
updateQualifiers: (newQualifiers: QualifiersType) => void; | ||
}; | ||
|
||
// Create the context | ||
const QualifiersContext = createContext<QualifiersContextType | undefined>( | ||
undefined | ||
); | ||
|
||
// Custom hook to use the qualifiers context | ||
export const useQualifiersContext = () => { | ||
const context = useContext(QualifiersContext); | ||
if (!context) { | ||
throw new Error( | ||
"useQualifiersContext must be used within a QualifiersProvider" | ||
); | ||
} | ||
return context; | ||
}; | ||
|
||
// Provider component | ||
export const QualifiersProvider: React.FC<{ children: ReactNode }> = ({ | ||
children, | ||
}) => { | ||
// Initial state for qualifiers only for testing purposes, actual data should be fetched once the user has an account, and then used to setQualifiers, by using useEffect | ||
const initialState: QualifiersType = { | ||
COPs: { | ||
// Uncomment data below for testing | ||
// "UI/UX": [ | ||
// "UI/UX_Designer", | ||
// "UX_Researcher", | ||
// "UX_Writing", | ||
// "UX_Practice_Lead", | ||
// ], | ||
// Data_Science: ["Data_Scientist", "Data_Analyst"], | ||
}, | ||
// availabilityTimeSlots: [], | ||
}; | ||
|
||
const [qualifiers, setQualifiers] = useState<QualifiersType>(initialState); | ||
|
||
const updateQualifiers = (newQualifiers: QualifiersType) => { | ||
setQualifiers(newQualifiers); | ||
}; | ||
|
||
return ( | ||
<QualifiersContext.Provider | ||
value={{ copData, qualifiers, updateQualifiers }} | ||
> | ||
{children} | ||
</QualifiersContext.Provider> | ||
); | ||
}; |
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
Oops, something went wrong.