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.
Refactored QualifiersPageRoles, added context, and updated documentat…
…aion on COP JSON structure
- Loading branch information
1 parent
fd766f0
commit 6cb423b
Showing
6 changed files
with
252 additions
and
73 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,61 @@ | ||
import React, { createContext, useContext, useState, ReactNode } from "react"; | ||
|
||
// Types | ||
type QualifiersType = { | ||
COPs: { | ||
[copName: string]: string[]; | ||
}; | ||
// availabilityTimeSlots: string[]; | ||
}; | ||
|
||
type QualifiersContextType = { | ||
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, should be fetched once the user has an account | ||
const initialState: QualifiersType = { | ||
COPs: { | ||
// // Data below is for testing | ||
// "UI/UX": [ | ||
// "UI/UX Designer", | ||
// "UX Researcher", | ||
// "UX Writing", | ||
// "UX Practice Lead", | ||
// ], | ||
}, | ||
// availabilityTimeSlots: [], | ||
}; | ||
|
||
const [qualifiers, setQualifiers] = useState<QualifiersType>(initialState); | ||
|
||
const updateQualifiers = (newQualifiers: QualifiersType) => { | ||
setQualifiers(newQualifiers); | ||
}; | ||
|
||
return ( | ||
<QualifiersContext.Provider value={{ 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.