-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into PROD-2130-BE-add-query-param-key-to-privacy-…
…center-config
- Loading branch information
Showing
15 changed files
with
139 additions
and
102 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,16 @@ | ||
export const raise = (message: string) => { | ||
throw new Error(message); | ||
}; | ||
|
||
/** | ||
* Extracts the id value of each object in the list and returns a list | ||
* of IDs, either strings or numbers based on the IDs' type. | ||
*/ | ||
export const extractIds = <T extends { id: string | number }[]>( | ||
modelList?: T | ||
): any[] => { | ||
if (!modelList) { | ||
return []; | ||
} | ||
return modelList.map((model) => model.id); | ||
}; |
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,4 @@ | ||
export { default as useConsentServed } from "./useConsentServed"; | ||
export { default as useHasMounted } from "./useHasMounted"; | ||
export { default as useUUID4 } from "./useUUID4"; | ||
export { default as useDisclosure } from "./useDisclosure"; |
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,41 @@ | ||
import { useCallback, useState } from "preact/hooks"; | ||
|
||
/** | ||
* Hook to facilitate showing/hiding while adhering to WAI | ||
* based on chakra-ui's `useDisclosure` | ||
*/ | ||
const useDisclosure = ({ id }: { id: string }) => { | ||
const [isOpen, setIsOpen] = useState(false); | ||
|
||
const onClose = useCallback(() => setIsOpen(false), []); | ||
const onOpen = useCallback(() => setIsOpen(true), []); | ||
|
||
const onToggle = useCallback(() => { | ||
if (isOpen) { | ||
onClose(); | ||
} else { | ||
onOpen(); | ||
} | ||
}, [isOpen, onOpen, onClose]); | ||
|
||
const getButtonProps = () => ({ | ||
"aria-expanded": isOpen, | ||
"aria-controls": id, | ||
onClick: onToggle, | ||
}); | ||
|
||
const getDisclosureProps = () => ({ | ||
id, | ||
className: isOpen ? "fides-disclosure-visible" : "fides-disclosure-hidden", | ||
}); | ||
|
||
return { | ||
isOpen, | ||
onOpen, | ||
onClose, | ||
onToggle, | ||
getButtonProps, | ||
getDisclosureProps, | ||
}; | ||
}; | ||
export default useDisclosure; |
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,18 @@ | ||
import { useEffect, useState } from "preact/hooks"; | ||
|
||
/** | ||
* Hook which tracks if the app has mounted yet. | ||
* | ||
* Used to make sure the server and client UIs match for hydration | ||
* Adapted from https://www.joshwcomeau.com/react/the-perils-of-rehydration/ | ||
*/ | ||
const useHasMounted = () => { | ||
const [hasMounted, setHasMounted] = useState(false); | ||
|
||
useEffect(() => { | ||
setHasMounted(true); | ||
}, []); | ||
|
||
return hasMounted; | ||
}; | ||
export default useHasMounted; |
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,14 @@ | ||
import { useState } from "preact/hooks"; | ||
import { v4 as uuidv4 } from "uuid"; | ||
|
||
/** | ||
* Custom hook that generates a UUIDv4. | ||
* The returned value stays the same for the lifetime of the component. | ||
* @returns The generated UUIDv4. | ||
*/ | ||
const useUUID4 = () => { | ||
const [uuid] = useState<string>(uuidv4()); | ||
|
||
return uuid; | ||
}; | ||
export default useUUID4; |
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.