Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/cyan-kids-jump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@clerk/ui': patch
---

Fix `TaskChooseOrganization` to complete organization activation when logo upload fails
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { useOrganizationList } from '@clerk/shared/react';
import type { CreateOrganizationParams, OrganizationCreationDefaultsResource } from '@clerk/shared/types';
import type {
CreateOrganizationParams,
OrganizationCreationDefaultsResource,
OrganizationResource,
} from '@clerk/shared/types';
import { useState } from 'react';

import { useEnvironment } from '@/ui/contexts';
Expand Down Expand Up @@ -64,14 +68,9 @@ export const CreateOrganizationScreen = (props: CreateOrganizationScreenProps) =

const organization = await createOrganization(createOrgParams);

if (file) {
await organization.setLogo({ file });
} else if (defaultLogoUrl) {
const response = await fetch(defaultLogoUrl);
const blob = await response.blob();
const logoFile = new File([blob], 'logo', { type: blob.type });
await organization.setLogo({ file: logoFile });
}
// If setting the logo fails, we still want to set the active organization
const uploadOrganizationLogoPromise = uploadOrganizationLogo(organization);
await Promise.allSettled([uploadOrganizationLogoPromise]);

await setActive({
organization,
Expand All @@ -84,6 +83,17 @@ export const CreateOrganizationScreen = (props: CreateOrganizationScreenProps) =
}
};

const uploadOrganizationLogo = async (organization: OrganizationResource) => {
if (file) {
await organization.setLogo({ file });
} else if (defaultLogoUrl) {
const response = await fetch(defaultLogoUrl);
const blob = await response.blob();
const logoFile = new File([blob], 'logo', { type: blob.type });
await organization.setLogo({ file: logoFile });
}
};

const onChangeName = (event: React.ChangeEvent<HTMLInputElement>) => {
nameField.setValue(event.target.value);
updateSlugField(createSlug(event.target.value));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,66 @@
import type { OrganizationResource } from '@clerk/shared/src/types';
import { waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { beforeEach, describe, expect, it } from 'vitest';
import { beforeEach, describe, expect, it, vi } from 'vitest';

import { clearFetchCache } from '@/ui/hooks/useFetch';
import { bindCreateFixtures } from '@/test/create-fixtures';
import { render } from '@/test/utils';
import {
createFakeUserOrganizationMembership,
createFakeUserOrganizationSuggestion,
} from '@/ui/components/OrganizationSwitcher/__tests__/test-utils';
import { clearFetchCache } from '@/ui/hooks/useFetch';

import { TaskChooseOrganization } from '..';
import type { FakeOrganizationParams } from '../../../../CreateOrganization/__tests__/CreateOrganization.test';

type FakeOrganizationParams = {
id: string;
createdAt?: Date;
imageUrl?: string;
slug: string;
name: string;
membersCount: number;
pendingInvitationsCount: number;
adminDeleteEnabled: boolean;
maxAllowedMemberships: number;
};
Comment on lines +15 to +27
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

cat -n packages/ui/src/components/SessionTasks/tasks/TaskChooseOrganization/__tests__/TaskChooseOrganization.test.tsx | head -30

Repository: clerk/javascript

Length of output: 1275


🏁 Script executed:

grep -n "FakeOrganizationParams" packages/ui/src/components/CreateOrganization/__tests__/CreateOrganization.test.tsx | head -20

Repository: clerk/javascript

Length of output: 272


Remove the duplicate FakeOrganizationParams type declaration.

Line 14 imports FakeOrganizationParams from the CreateOrganization test file, but lines 16–26 re-declare it locally. This duplicate identifier causes a TypeScript compiler error that blocks the build.

Suggested fix
-import type { FakeOrganizationParams } from '../../../../CreateOrganization/__tests__/CreateOrganization.test';
-
-type FakeOrganizationParams = {
-  id: string;
-  createdAt?: Date;
-  imageUrl?: string;
-  slug: string;
-  name: string;
-  membersCount: number;
-  pendingInvitationsCount: number;
-  adminDeleteEnabled: boolean;
-  maxAllowedMemberships: number;
-};

Keep only the import and use the imported type.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
import type { FakeOrganizationParams } from '../../../../CreateOrganization/__tests__/CreateOrganization.test';
type FakeOrganizationParams = {
id: string;
createdAt?: Date;
imageUrl?: string;
slug: string;
name: string;
membersCount: number;
pendingInvitationsCount: number;
adminDeleteEnabled: boolean;
maxAllowedMemberships: number;
};
import type { FakeOrganizationParams } from '../../../../CreateOrganization/__tests__/CreateOrganization.test';
🧰 Tools
🪛 Biome (2.1.2)

[error] 16-16: Shouldn't redeclare 'FakeOrganizationParams'. Consider to delete it or rename it.

'FakeOrganizationParams' is defined here:

(lint/suspicious/noRedeclare)

🤖 Prompt for AI Agents
In
`@packages/ui/src/components/SessionTasks/tasks/TaskChooseOrganization/__tests__/TaskChooseOrganization.test.tsx`
around lines 14 - 26, Remove the locally redeclared FakeOrganizationParams type
in TaskChooseOrganization.test.tsx and rely on the imported
FakeOrganizationParams (import type { FakeOrganizationParams } ...) instead;
delete the duplicate type block (the type declaration that lists id, createdAt,
imageUrl, slug, name, membersCount, pendingInvitationsCount, adminDeleteEnabled,
maxAllowedMemberships) so only the imported symbol FakeOrganizationParams
remains used in the test.


const createFakeOrganization = (params: FakeOrganizationParams): OrganizationResource => {
return {
pathRoot: '',
id: params.id,
name: params.name,
slug: params.slug,
hasImage: !!params.imageUrl,
imageUrl: params.imageUrl || '',
membersCount: params.membersCount,
pendingInvitationsCount: params.pendingInvitationsCount,
publicMetadata: {},
adminDeleteEnabled: params.adminDeleteEnabled,
maxAllowedMemberships: params?.maxAllowedMemberships,
createdAt: params?.createdAt || new Date(),
updatedAt: new Date(),
update: vi.fn() as any,
getMemberships: vi.fn() as any,
getInvitations: vi.fn() as any,
getRoles: vi.fn() as any,
addMember: vi.fn() as any,
inviteMember: vi.fn() as any,
inviteMembers: vi.fn() as any,
updateMember: vi.fn() as any,
removeMember: vi.fn() as any,
createDomain: vi.fn() as any,
getDomain: vi.fn() as any,
getDomains: vi.fn() as any,
getMembershipRequests: vi.fn() as any,
destroy: vi.fn() as any,
setLogo: vi.fn() as any,
reload: vi.fn() as any,
__internal_toSnapshot: vi.fn() as any,
initializePaymentMethod: vi.fn() as any,
} as OrganizationResource;
};

const { createFixtures } = bindCreateFixtures('TaskChooseOrganization');

Expand Down Expand Up @@ -443,4 +494,49 @@ describe('TaskChooseOrganization', () => {
});
});
});

describe('on create organization submit', () => {
it('calls setActive even when logo upload fails', async () => {
const { wrapper, fixtures } = await createFixtures(f => {
f.withOrganizations();
f.withForceOrganizationSelection();
f.withUser({
email_addresses: ['test@clerk.com'],
create_organization_enabled: true,
tasks: [{ key: 'choose-organization' }],
});
});

const createdOrg = createFakeOrganization({
id: '1',
adminDeleteEnabled: false,
maxAllowedMemberships: 1,
membersCount: 1,
name: 'new org',
pendingInvitationsCount: 0,
slug: 'new-org',
});

// Mock setLogo to reject with an error
createdOrg.setLogo = vi.fn().mockRejectedValue(new Error('Logo upload failed'));

fixtures.clerk.createOrganization.mockReturnValue(Promise.resolve(createdOrg));

const { findByRole, findByLabelText } = render(<TaskChooseOrganization />, { wrapper });

const nameInput = await findByLabelText(/name/i);
await userEvent.type(nameInput, 'new org');

const submitButton = await findByRole('button', { name: /continue/i });
await userEvent.click(submitButton);

await waitFor(() => {
expect(fixtures.clerk.setActive).toHaveBeenCalledWith(
expect.objectContaining({
organization: createdOrg,
}),
);
});
});
});
});
Loading