Skip to content

feat(clerk-js): Add organization basic resources#57

Merged
igneel64 merged 10 commits into
mainfrom
organization_clerk_js
Mar 3, 2022
Merged

feat(clerk-js): Add organization basic resources#57
igneel64 merged 10 commits into
mainfrom
organization_clerk_js

Conversation

@igneel64
Copy link
Copy Markdown
Contributor

Type of change

  • 🐛 Bug fix
  • 🌟 New feature
  • 🔨 Breaking change
  • 📖 Refactoring / dependency upgrade / documentation
  • other:

Packages affected

  • @clerk/clerk-js
  • @clerk/clerk-react
  • @clerk/nextjs
  • @clerk/types
  • @clerk/clerk-expo
  • @clerk/backend-core
  • @clerk/clerk-sdk-node
  • @clerk/edge
  • build/tooling/chore

Description

  • npm test runs as expected.
  • npm run build runs as expected.

First iteration of the organizations base resources:

  • Organization
  • OrganizationMembership
  • OrganizationInvitation

@igneel64 igneel64 marked this pull request as draft February 22, 2022 12:11
@igneel64 igneel64 force-pushed the organization_clerk_js branch from 26c5337 to 09f9012 Compare February 22, 2022 13:29
Copy link
Copy Markdown
Contributor

@SokratisVidros SokratisVidros left a comment

Choose a reason for hiding this comment

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

@igneel64 As discussed we should align all models to use this._baseX(X=Post,Put, etc...) method for XHR requests.

})
.then(res => {
const organizationsJSON = res.payload
?.response as unknown as OrganizationJSON[];
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

❓ Just asking, why is the type assertion needed here?

I'd expect that we wouldn't need it because of the generic param in line 48:

 .request<OrganizationJSON[]>({

Is this type broken?

this.fromJSON(data);
}

static async create(name: string): Promise<OrganizationResource> {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

❓ IIRC, all resources use the this.basePost | this.baseGet | ... methods that retrieve a json and return the instantiated resource. Why did we decide to use the static BaseResource._fetch here?

To be honest, I'm not a huge fan of the this.basePost approach, but if we don't have any specific reasons to do otherwise, I think it'd be better to remain consistent and tackle them all at once in a different PR

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@nikosdouvlis
Discussed offline.

@igneel64 igneel64 force-pushed the organization_clerk_js branch from 2e21552 to 1635132 Compare March 2, 2022 09:35
@igneel64 igneel64 marked this pull request as ready for review March 2, 2022 09:50
@igneel64 igneel64 changed the title WIP: feat(clerk-js): Add organization basic resources feat(clerk-js): Add organization basic resources Mar 2, 2022
this.#fapiClient.onAfterResponse(callback);
}

__unstable_inviteMember = async (
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@igneel64 Can you please elaborate why do we consider this an unstable method at this point?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

❓ A follow up question, does this method invite a member or creates an org? Something seems to be missing.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@SokratisVidros , thanks for the comment.

The use of the __unstable prefix is intended here. Currently we cannot expose methods on clerk-react from internal clerk-js resources. The only way this can be done is through the Clerk interface.
The same interface though is exposed globally. That means that adding a method there, it is also exposed in window.Clerk.methodName.
Since adding methods indiscriminately on the global Clerk object is not the optimal outcome, for now we are adding to those methods the __unstable prefix to prevent misuse.

(Also this method just invites a member on an organization. The organizations can be retrieved from the useOrganizations hook.)

Comment thread packages/clerk-js/src/core/resources/Organization.ts Outdated
Comment thread packages/clerk-js/src/utils/getClerkQueryParam.ts
Comment thread packages/react/src/hooks/useOrganization.ts
const clerk = useClerk();

return {
createOrganization: clerk.createOrganization,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔧 Ditto about listing orgs.

@igneel64 igneel64 force-pushed the organization_clerk_js branch from 087735f to 080c50b Compare March 3, 2022 09:37
Comment thread packages/react/src/hooks/useOrganizations.ts Outdated
…mechanism alignment

Fix state clearing of organizationInvitationToken
@igneel64 igneel64 force-pushed the organization_clerk_js branch from 080c50b to fc11087 Compare March 3, 2022 12:03
@igneel64 igneel64 requested a review from SokratisVidros March 3, 2022 12:03
Copy link
Copy Markdown
Contributor

@SokratisVidros SokratisVidros left a comment

Choose a reason for hiding this comment

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

💯

@igneel64 igneel64 merged commit c0f1a6d into main Mar 3, 2022
@igneel64 igneel64 deleted the organization_clerk_js branch March 3, 2022 13:04
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Jun 11, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants