-
Notifications
You must be signed in to change notification settings - Fork 259
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(clerk-js,shared): Introduce OrganizationMembershipRequest and me…
…mbershipRequests within useOrganization (#1572) * feat(clerk-js): Introduce OrganizationMembershipRequest resource * feat(shared): Introduce membershipRequests in useOrganization * test(clerk-js): Update snapshots of Organization and OrganizationMembership * test(clerk-js): Add snapshots test for OrganizationMembershipRequest * chore(clerk-js): Add changeset
- Loading branch information
1 parent
3158752
commit 96cc192
Showing
13 changed files
with
255 additions
and
75 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
'@clerk/clerk-js': patch | ||
'@clerk/shared': patch | ||
'@clerk/types': patch | ||
--- | ||
|
||
Introduces a new resource called OrganizationMembership | ||
|
||
+ useOrganization has been updated in order to return a list of domain with the above type |
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
26 changes: 26 additions & 0 deletions
26
packages/clerk-js/src/core/resources/OrganizationMembershipRequest.test.ts
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,26 @@ | ||
import { OrganizationMembershipRequest } from './internal'; | ||
|
||
describe('OrganizationMembership', () => { | ||
it('has the same initial properties', () => { | ||
const organizationMembershipRequest = new OrganizationMembershipRequest({ | ||
object: 'organization_membership_request', | ||
id: 'test_id', | ||
organization_id: 'test_org_id', | ||
status: 'pending', | ||
created_at: 12345, | ||
updated_at: 5678, | ||
public_user_data: { | ||
object: 'public_user_data', | ||
first_name: 'test_first_name', | ||
last_name: 'test_last_name', | ||
profile_image_url: 'test_url', | ||
image_url: 'https://clerk.com', | ||
identifier: 'test@identifier.gr', | ||
id: 'test_user_id', | ||
has_image: true, | ||
}, | ||
}); | ||
|
||
expect(organizationMembershipRequest).toMatchSnapshot(); | ||
}); | ||
}); |
44 changes: 44 additions & 0 deletions
44
packages/clerk-js/src/core/resources/OrganizationMembershipRequest.ts
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,44 @@ | ||
import type { OrganizationInvitationStatus, OrganizationMembershipRequestResource, PublicUserData } from '@clerk/types'; | ||
import type { OrganizationMembershipRequestJSON } from '@clerk/types'; | ||
|
||
import { BaseResource } from './Base'; | ||
|
||
export class OrganizationMembershipRequest extends BaseResource implements OrganizationMembershipRequestResource { | ||
id!: string; | ||
organizationId!: string; | ||
status!: OrganizationInvitationStatus; | ||
publicUserData!: PublicUserData; | ||
createdAt!: Date; | ||
updatedAt!: Date; | ||
|
||
constructor(data: OrganizationMembershipRequestJSON) { | ||
super(); | ||
this.fromJSON(data); | ||
} | ||
|
||
accept = async (): Promise<OrganizationMembershipRequestResource> => { | ||
return await this._basePost({ | ||
path: `/organizations/${this.organizationId}/membership_requests/${this.id}/accept`, | ||
}); | ||
}; | ||
|
||
protected fromJSON(data: OrganizationMembershipRequestJSON | null): this { | ||
if (data) { | ||
this.id = data.id; | ||
this.organizationId = data.organization_id; | ||
this.status = data.status; | ||
if (data.public_user_data) { | ||
this.publicUserData = { | ||
firstName: data.public_user_data.first_name, | ||
lastName: data.public_user_data.last_name, | ||
profileImageUrl: data.public_user_data.profile_image_url, | ||
imageUrl: data.public_user_data.image_url, | ||
hasImage: data.public_user_data.has_image, | ||
identifier: data.public_user_data.identifier, | ||
userId: data.public_user_data.user_id, | ||
}; | ||
} | ||
} | ||
return this; | ||
} | ||
} |
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
20 changes: 20 additions & 0 deletions
20
...ages/clerk-js/src/core/resources/__snapshots__/OrganizationMembershipRequest.test.ts.snap
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,20 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`OrganizationMembership has the same initial properties 1`] = ` | ||
OrganizationMembershipRequest { | ||
"accept": [Function], | ||
"id": "test_id", | ||
"organizationId": "test_org_id", | ||
"pathRoot": "", | ||
"publicUserData": { | ||
"firstName": "test_first_name", | ||
"hasImage": true, | ||
"identifier": "test@identifier.gr", | ||
"imageUrl": "https://clerk.com", | ||
"lastName": "test_last_name", | ||
"profileImageUrl": "test_url", | ||
"userId": undefined, | ||
}, | ||
"status": "pending", | ||
} | ||
`; |
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.