-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into CHI-1976-case_timeline_rework
# Conflicts: # plugin-hrm-form/src/components/case/CaseHome.tsx # plugin-hrm-form/src/components/case/timeline/Timeline.tsx
- Loading branch information
Showing
33 changed files
with
449 additions
and
108 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/** | ||
* Copyright (C) 2021-2023 Technology Matters | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published | ||
* by the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see https://www.gnu.org/licenses/. | ||
*/ | ||
import { ProfileIdParam } from '../selectors'; | ||
|
||
export type UseProfileCommonParams = { | ||
profileId: ProfileIdParam; | ||
}; |
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
65 changes: 65 additions & 0 deletions
65
plugin-hrm-form/src/states/profile/hooks/useProfileLoader.ts
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,65 @@ | ||
/** | ||
* Copyright (C) 2021-2023 Technology Matters | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published | ||
* by the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see https://www.gnu.org/licenses/. | ||
*/ | ||
import { useCallback, useEffect } from 'react'; | ||
import { useDispatch, useSelector } from 'react-redux'; | ||
|
||
import { RootState } from '../..'; | ||
import asyncDispatch from '../../asyncDispatch'; | ||
import * as ProfileActions from '../profiles'; | ||
import * as ProfileSelectors from '../selectors'; | ||
import { UseProfileCommonParams } from './types'; | ||
|
||
type UseProfileLoaderParams = UseProfileCommonParams & { | ||
skipAutoload?: boolean; | ||
}; | ||
|
||
type UseProfileLoaderReturn = { | ||
error?: any; | ||
loading: boolean; | ||
loadProfile: () => void; | ||
}; | ||
|
||
/** | ||
* Tools to load a profile by id into redux, by default it will load the profile automatically | ||
* @param {UseProfileLoaderParams} params - Parameters for the hook | ||
* @param params.profileId - The id of the profile to load | ||
* @param params.skipAutoload - If true, the profile will not be loaded automatically (default: false) | ||
* @returns {UseProfileLoaderReturn} - loading state and actions for the profile | ||
*/ | ||
export const useProfileLoader = ({ | ||
profileId, | ||
skipAutoload = false, | ||
}: UseProfileLoaderParams): UseProfileLoaderReturn => { | ||
const dispatch = useDispatch(); | ||
const error = useSelector((state: RootState) => ProfileSelectors.selectProfileById(state, profileId)?.error); | ||
const loading = useSelector((state: RootState) => ProfileSelectors.selectProfileById(state, profileId)?.loading); | ||
const loadProfile = useCallback(() => { | ||
asyncDispatch(dispatch)(ProfileActions.loadProfileAsync(profileId)); | ||
}, [dispatch, profileId]); | ||
|
||
useEffect(() => { | ||
if (!skipAutoload && !loading) { | ||
loadProfile(); | ||
} | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [profileId, skipAutoload, loadProfile]); | ||
|
||
return { | ||
error, | ||
loading, | ||
loadProfile, | ||
}; | ||
}; |
33 changes: 33 additions & 0 deletions
33
plugin-hrm-form/src/states/profile/hooks/useProfileProperty.ts
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,33 @@ | ||
/** | ||
* Copyright (C) 2021-2023 Technology Matters | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published | ||
* by the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see https://www.gnu.org/licenses/. | ||
*/ | ||
import { useSelector } from 'react-redux'; | ||
|
||
import { RootState } from '../..'; | ||
import { Profile } from '../types'; | ||
import * as ProfileSelectors from '../selectors'; | ||
|
||
/** | ||
* Access a profile property by id for the current account | ||
* | ||
* @param {ProfileSelectors.ProfileIdParam} profileId - The id of the profile to access | ||
* @param {T} property - The property to access | ||
* @returns {UseProfile} - State and actions for the profile | ||
*/ | ||
export const useProfileProperty = <T extends keyof Profile>( | ||
profileId: ProfileSelectors.ProfileIdParam, | ||
property: T, | ||
): Profile[T] | undefined => | ||
useSelector((state: RootState) => ProfileSelectors.selectProfilePropertyById(state, profileId, property)); |
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.