Skip to content

Commit 2e78889

Browse files
committed
chore(clerk-js): Fix minor discrepancies
1 parent c113cb9 commit 2e78889

File tree

3 files changed

+43
-41
lines changed

3 files changed

+43
-41
lines changed

packages/clerk-js/src/ui/components/OrganizationSwitcher/OtherOrganizationActions.tsx

Lines changed: 22 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,6 @@ type OrganizationActionListProps = {
2727
onOrganizationClick: (org: OrganizationResource) => unknown;
2828
};
2929

30-
export interface IntersectionOptions extends IntersectionObserverInit {
31-
/** Only trigger the inView callback once */
32-
triggerOnce?: boolean;
33-
/** Call this function whenever the in view state changes */
34-
onChange?: (inView: boolean, entry: IntersectionObserverEntry) => void;
35-
}
36-
3730
export const OrganizationActionList = (props: OrganizationActionListProps) => {
3831
const { onCreateOrganizationClick, onPersonalWorkspaceClick, onOrganizationClick } = props;
3932
const { organizationList, userInvitations } = useCoreOrganizationList({
@@ -46,7 +39,7 @@ export const OrganizationActionList = (props: OrganizationActionListProps) => {
4639
threshold: 0,
4740
onChange: inView => {
4841
if (inView) {
49-
void userInvitations.fetchNext?.();
42+
userInvitations.fetchNext?.();
5043
}
5144
},
5245
});
@@ -119,20 +112,18 @@ export const OrganizationActionList = (props: OrganizationActionListProps) => {
119112

120113
{(userInvitations.count ?? 0) > 0 && (
121114
<Flex
122-
direction={'col'}
115+
direction='col'
123116
elementDescriptor={descriptors.organizationSwitcherPopoverInvitationActions}
124117
>
125118
<Text
126-
variant={'smallRegular'}
127-
sx={[
128-
t => ({
129-
minHeight: 'unset',
130-
height: t.space.$12,
131-
padding: `${t.space.$3} ${t.space.$6}`,
132-
display: 'flex',
133-
alignItems: 'center',
134-
}),
135-
]}
119+
variant='smallRegular'
120+
sx={t => ({
121+
minHeight: 'unset',
122+
height: t.space.$12,
123+
padding: `${t.space.$3} ${t.space.$6}`,
124+
display: 'flex',
125+
alignItems: 'center',
126+
})}
136127
// Handle plurals
137128
localizationKey={localizationKeys(
138129
(userInvitations.count ?? 0) > 1
@@ -162,13 +153,11 @@ export const OrganizationActionList = (props: OrganizationActionListProps) => {
162153
{(userInvitations.hasNextPage || userInvitations.isFetching) && (
163154
<Box
164155
ref={ref}
165-
sx={[
166-
t => ({
167-
width: '100%',
168-
height: t.space.$12,
169-
position: 'relative',
170-
}),
171-
]}
156+
sx={t => ({
157+
width: '100%',
158+
height: t.space.$12,
159+
position: 'relative',
160+
})}
172161
>
173162
<Box
174163
sx={{
@@ -230,16 +219,14 @@ const AcceptRejectInvitationButtons = (props: UserOrganizationInvitationResource
230219
const InvitationPreview = withCardStateProvider((props: UserOrganizationInvitationResource) => {
231220
return (
232221
<Flex
233-
align={'center'}
222+
align='center'
234223
gap={2}
235-
sx={[
236-
t => ({
237-
minHeight: 'unset',
238-
height: t.space.$12,
239-
justifyContent: 'space-between',
240-
padding: `0 ${t.space.$6}`,
241-
}),
242-
]}
224+
sx={t => ({
225+
minHeight: 'unset',
226+
height: t.space.$12,
227+
justifyContent: 'space-between',
228+
padding: `0 ${t.space.$6}`,
229+
})}
243230
>
244231
<OrganizationPreview
245232
elementId={'organizationSwitcher'}

packages/clerk-js/src/ui/components/OrganizationSwitcher/__tests__/OrganizationSwitcher.test.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,6 @@ describe('OrganizationSwitcher', () => {
175175
expect(queryByText('OrgTwo')).toBeInTheDocument();
176176
});
177177

178-
it.todo('switches between active organizations when one is clicked');
179178
it("switches between active organizations when one is clicked'", async () => {
180179
const { wrapper, props, fixtures } = await createFixtures(f => {
181180
f.withOrganizations();

packages/clerk-js/src/ui/hooks/useInView.ts

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,32 @@
1-
import React, { useCallback, useRef, useState } from 'react';
2-
3-
import type { IntersectionOptions } from '../components/OrganizationSwitcher/OtherOrganizationActions';
4-
1+
import { useCallback, useRef, useState } from 'react';
2+
3+
interface IntersectionOptions extends IntersectionObserverInit {
4+
/** Only trigger the inView callback once */
5+
triggerOnce?: boolean;
6+
/** Call this function whenever the in view state changes */
7+
onChange?: (inView: boolean, entry: IntersectionObserverEntry) => void;
8+
}
9+
10+
/**
11+
* A custom React hook that provides the ability to track whether an element is in view
12+
* based on the IntersectionObserver API.
13+
*
14+
* @param {IntersectionOptions} params - IntersectionObserver configuration options.
15+
* @returns {{
16+
* inView: boolean,
17+
* ref: (element: HTMLElement | null) => void
18+
* }} An object containing the current inView status and a ref function to attach to the target element.
19+
*/
520
export const useInView = (params: IntersectionOptions) => {
621
const [inView, setInView] = useState(false);
722
const observerRef = useRef<IntersectionObserver | null>(null);
823
const thresholds = Array.isArray(params.threshold) ? params.threshold : [params.threshold || 0];
9-
const internalOnChange = React.useRef<IntersectionOptions['onChange']>();
24+
const internalOnChange = useRef<IntersectionOptions['onChange']>();
1025

1126
internalOnChange.current = params.onChange;
1227

1328
const ref = useCallback((element: HTMLElement | null) => {
29+
// Callback refs are called with null to clear the value, so we rely on that to cleanup the observer. (ref: https://react.dev/learn/manipulating-the-dom-with-refs#how-to-manage-a-list-of-refs-using-a-ref-callback)
1430
if (!element) {
1531
if (observerRef.current) {
1632
observerRef.current.disconnect();

0 commit comments

Comments
 (0)