Skip to content

Commit 2ffafe7

Browse files
Merge pull request #129 from auth0/feat/unified-hooks-org-details
feat(react): refactor org details with view props
2 parents 17c1794 + b8e3dd0 commit 2ffafe7

4 files changed

Lines changed: 40 additions & 90 deletions

File tree

packages/react/src/components/auth0/my-organization/__tests__/organization-details-edit.test.tsx

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ import {
1010
import * as useCoreClientModule from '@/hooks/shared/use-core-client';
1111
import {
1212
createMockOrganization,
13-
createMockOrganizationDetailsEditHandler,
14-
createMockOrganizationDetailsEditLogic,
13+
createMockOrganizationDetailsEditView,
1514
} from '@/tests/utils/__mocks__/my-organization/organization-management/organization-details.mocks';
1615
import { renderWithProviders } from '@/tests/utils/test-provider';
1716
import { mockCore, mockToast } from '@/tests/utils/test-setup';
@@ -539,60 +538,44 @@ describe('OrganizationDetailsEdit', () => {
539538
});
540539

541540
describe('OrganizationDetailsEditView', () => {
542-
const logic = { ...createMockOrganizationDetailsEditLogic(), currentStyles: undefined };
543-
const handlers = createMockOrganizationDetailsEditHandler();
541+
const viewProps = createMockOrganizationDetailsEditView();
544542

545543
it('renders the header and organization details form', () => {
546-
renderWithProviders(<OrganizationDetailsEditView logic={logic} handlers={handlers} />);
544+
renderWithProviders(<OrganizationDetailsEditView {...viewProps} />);
547545
expect(screen.getByRole('banner')).toBeInTheDocument();
548546
expect(screen.getByTestId('organization-details-card')).toBeInTheDocument();
549547
});
550548

551549
it('renders custom card class if provided', () => {
552550
renderWithProviders(
553551
<OrganizationDetailsEditView
554-
logic={{
555-
...logic,
556-
styling: {
557-
...logic.styling,
558-
classes: { ...logic.styling.classes, OrganizationDetails_Card: 'custom-card-class' },
559-
},
552+
{...viewProps}
553+
styling={{
554+
...viewProps.styling,
555+
classes: { ...viewProps.styling.classes, OrganizationDetails_Card: 'custom-card-class' },
560556
}}
561-
handlers={handlers}
562557
/>,
563558
);
564559
expect(document.querySelector('.custom-card-class')).toBeInTheDocument();
565560
});
566561

567562
it('does not render header if hideHeader is true', () => {
568-
renderWithProviders(
569-
<OrganizationDetailsEditView logic={{ ...logic, hideHeader: true }} handlers={handlers} />,
570-
);
563+
renderWithProviders(<OrganizationDetailsEditView {...viewProps} hideHeader={true} />);
571564
expect(screen.queryByRole('banner')).not.toBeInTheDocument();
572565
});
573566

574567
it('renders with customMessages', () => {
575568
renderWithProviders(
576569
<OrganizationDetailsEditView
577-
logic={{
578-
...logic,
579-
customMessages: {
580-
header: { title: 'Custom Title', back_button_text: 'Back' },
581-
},
582-
}}
583-
handlers={handlers}
570+
{...viewProps}
571+
customMessages={{ header: { title: 'Custom Title', back_button_text: 'Back' } }}
584572
/>,
585573
);
586574
expect(screen.getByText(/custom title/i)).toBeInTheDocument();
587575
});
588576

589577
it('renders loading state when isFetchLoading is true', () => {
590-
renderWithProviders(
591-
<OrganizationDetailsEditView
592-
logic={{ ...logic, isFetchLoading: true }}
593-
handlers={handlers}
594-
/>,
595-
);
578+
renderWithProviders(<OrganizationDetailsEditView {...viewProps} isFetchLoading={true} />);
596579
expect(screen.getByText('Loading...')).toBeInTheDocument();
597580
});
598581
});

packages/react/src/components/auth0/my-organization/organization-details-edit.tsx

Lines changed: 24 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,11 @@ import { useTheme } from '@/hooks/shared/use-theme';
1212
import { useTranslator } from '@/hooks/shared/use-translator';
1313
import type {
1414
OrganizationDetailsEditProps,
15-
OrganizationDetailsEditLogicProps,
16-
OrganizationDetailsEditHandlerProps,
1715
OrganizationDetailsEditViewProps,
1816
} from '@/types/my-organization/organization-management/organization-details-edit-types';
1917

2018
/**
21-
* Internal organization details edit container component.
19+
* Organization details edit component.
2220
* @param props - Component props
2321
* @param props.schema - Zod validation schema
2422
* @param props.customMessages - Custom translation messages to override defaults
@@ -31,7 +29,7 @@ import type {
3129
* @returns JSX element
3230
* @internal
3331
*/
34-
function OrganizationDetailsEditContainer(props: OrganizationDetailsEditProps): React.JSX.Element {
32+
function OrganizationDetailsEdit(props: OrganizationDetailsEditProps): React.JSX.Element {
3533
const {
3634
schema,
3735
customMessages = {},
@@ -53,47 +51,37 @@ function OrganizationDetailsEditContainer(props: OrganizationDetailsEditProps):
5351
customMessages,
5452
});
5553

56-
const orgDetailsEditLogicProps: OrganizationDetailsEditLogicProps = {
57-
organization,
58-
isFetchLoading,
59-
schema,
60-
styling,
61-
customMessages,
62-
readOnly,
63-
hideHeader,
64-
backButton,
65-
};
66-
67-
const orgDetailsEditHandlerProps: OrganizationDetailsEditHandlerProps = {
68-
formActions,
69-
};
70-
7154
return (
7255
<OrganizationDetailsEditView
73-
logic={orgDetailsEditLogicProps}
74-
handlers={orgDetailsEditHandlerProps}
56+
organization={organization}
57+
isFetchLoading={isFetchLoading}
58+
schema={schema}
59+
styling={styling}
60+
customMessages={customMessages}
61+
readOnly={readOnly}
62+
hideHeader={hideHeader}
63+
backButton={backButton}
64+
formActions={formActions}
7565
/>
7666
);
7767
}
7868

7969
/**
80-
* OrganizationDetailsEditView — Presentational component.
81-
* @param props - View props with logic and handlers
82-
* @returns Organization Details Edit view element
8370
* @internal
71+
* @param props - View props
72+
* @returns Organization Details Edit view element
8473
*/
85-
function OrganizationDetailsEditView({ logic, handlers }: OrganizationDetailsEditViewProps) {
86-
const {
87-
organization,
88-
isFetchLoading,
89-
schema,
90-
styling,
91-
customMessages,
92-
readOnly,
93-
hideHeader,
94-
backButton,
95-
} = logic;
96-
const { formActions } = handlers;
74+
function OrganizationDetailsEditView({
75+
organization,
76+
isFetchLoading,
77+
schema,
78+
styling,
79+
customMessages,
80+
readOnly,
81+
hideHeader,
82+
backButton,
83+
formActions,
84+
}: OrganizationDetailsEditViewProps) {
9785
const { isDarkMode } = useTheme();
9886
const { t } = useTranslator('organization_management.organization_details_edit', customMessages);
9987

@@ -179,6 +167,4 @@ function OrganizationDetailsEditView({ logic, handlers }: OrganizationDetailsEdi
179167
* />
180168
* ```
181169
*/
182-
const OrganizationDetailsEdit = OrganizationDetailsEditContainer;
183-
184170
export { OrganizationDetailsEdit, OrganizationDetailsEditView };

packages/react/src/tests/utils/__mocks__/my-organization/organization-management/organization-details.mocks.ts

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import type { Organization } from '@auth0/universal-components-core';
22

3-
import type {
4-
OrganizationDetailsEditLogicProps,
5-
OrganizationDetailsEditHandlerProps,
6-
} from '@/types/my-organization/organization-management/organization-details-edit-types';
3+
import type { OrganizationDetailsEditViewProps } from '@/types/my-organization/organization-management/organization-details-edit-types';
74

85
export const createMockOrganization = (): Organization => ({
96
id: 'organization_abc123xyz456',
@@ -18,9 +15,9 @@ export const createMockOrganization = (): Organization => ({
1815
},
1916
});
2017

21-
export function createMockOrganizationDetailsEditLogic(
22-
overrides: Partial<OrganizationDetailsEditLogicProps> = {},
23-
): OrganizationDetailsEditLogicProps {
18+
export function createMockOrganizationDetailsEditView(
19+
overrides: Partial<OrganizationDetailsEditViewProps> = {},
20+
): OrganizationDetailsEditViewProps {
2421
return {
2522
organization: { ...createMockOrganization() },
2623
isFetchLoading: false,
@@ -30,14 +27,6 @@ export function createMockOrganizationDetailsEditLogic(
3027
readOnly: false,
3128
hideHeader: false,
3229
backButton: undefined,
33-
...overrides,
34-
};
35-
}
36-
37-
export function createMockOrganizationDetailsEditHandler(
38-
overrides: Partial<OrganizationDetailsEditHandlerProps> = {},
39-
): OrganizationDetailsEditHandlerProps {
40-
return {
4130
formActions: {
4231
isLoading: false,
4332
nextAction: {

packages/react/src/types/my-organization/organization-management/organization-details-edit-types.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export interface UseOrganizationDetailsEditResult {
6565
updateOrgDetails: (data: OrganizationPrivate) => Promise<boolean>;
6666
}
6767

68-
export interface OrganizationDetailsEditLogicProps {
68+
export interface OrganizationDetailsEditViewProps {
6969
organization: OrganizationPrivate;
7070
isFetchLoading: boolean;
7171
schema: Partial<OrganizationDetailsEditSchemas> | undefined;
@@ -74,13 +74,5 @@ export interface OrganizationDetailsEditLogicProps {
7474
readOnly: OrganizationDetailsEditProps['readOnly'];
7575
hideHeader: boolean;
7676
backButton?: OrganizationEditBackButton;
77-
}
78-
79-
export interface OrganizationDetailsEditHandlerProps {
8077
formActions: OrganizationDetailsFormActions;
8178
}
82-
83-
export interface OrganizationDetailsEditViewProps {
84-
logic: OrganizationDetailsEditLogicProps;
85-
handlers: OrganizationDetailsEditHandlerProps;
86-
}

0 commit comments

Comments
 (0)