-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #986 from Onlineberatung/OB-5604
feat: added specific agency provider to provide agency specific links
- Loading branch information
Showing
14 changed files
with
156 additions
and
36 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
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
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,39 @@ | ||
import * as React from 'react'; | ||
import { | ||
createContext, | ||
useState, | ||
useContext, | ||
Dispatch, | ||
SetStateAction, | ||
useEffect | ||
} from 'react'; | ||
import { UserDataContext } from './UserDataProvider'; | ||
import { AgencyDataInterface } from '../interfaces/UserDataInterface'; | ||
import useUrlParamsLoader from '../../utils/useUrlParamsLoader'; | ||
|
||
export const AgencySpecificContext = createContext<{ | ||
specificAgency: AgencyDataInterface; | ||
setSpecificAgency: Dispatch<SetStateAction<AgencyDataInterface>>; | ||
}>(null); | ||
|
||
export function AgencySpecificProvider(props) { | ||
const { userData } = useContext(UserDataContext); | ||
const { agency: urlAgency } = useUrlParamsLoader(); | ||
const [agency, setAgency] = useState<AgencyDataInterface>(); | ||
|
||
useEffect(() => { | ||
if (userData?.agencies?.length > 0) { | ||
setAgency(userData.agencies[0]); | ||
} else if (urlAgency) { | ||
setAgency(urlAgency); | ||
} | ||
}, [urlAgency, userData]); | ||
|
||
return ( | ||
<AgencySpecificContext.Provider | ||
value={{ specificAgency: agency, setSpecificAgency: setAgency }} | ||
> | ||
{props.children} | ||
</AgencySpecificContext.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
Oops, something went wrong.