-
Notifications
You must be signed in to change notification settings - Fork 3
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 #20 from SailingSteve/steveStaffClientJan27-440pm
Fix the search function when adding a member to a team in the drawer.
- Loading branch information
Showing
7 changed files
with
88 additions
and
68 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { useState } from 'react'; | ||
import { useConnectAppContext } from '../contexts/ConnectAppContext'; | ||
|
||
// When the function name starts with 'use' React treats it as a custom hook, and it can then access Context variables | ||
const useGetFullNamePreferred = (person) => { | ||
const { getAppContextValue } = useConnectAppContext(); | ||
const [allStaffList] = useState(getAppContextValue('allStaffList')); | ||
const [personId] = Object.values(person); // This is silly, but this is a proof of concept | ||
const foundPerson = allStaffList && allStaffList.find((onePerson) => onePerson.id === parseInt(personId)); | ||
let fullName = ''; | ||
if (foundPerson?.id >= 0) { | ||
if (foundPerson?.firstNamePreferred) { | ||
fullName += foundPerson.firstNamePreferred; | ||
} else if (foundPerson?.firstName) { | ||
fullName += foundPerson.firstName; | ||
} | ||
if (fullName.length > 0 && foundPerson.lastName) { | ||
fullName += ' '; | ||
} | ||
if (foundPerson?.lastName) { | ||
fullName += foundPerson.lastName; | ||
} | ||
} | ||
return fullName; | ||
}; | ||
|
||
export default useGetFullNamePreferred; |