-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sharing): Updated functions for editors
- Loading branch information
1 parent
7016ae8
commit 0d60e40
Showing
6 changed files
with
86 additions
and
4 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
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
23 changes: 23 additions & 0 deletions
23
src/api-calls/homebrew/editorFunction/acceptEditorInvite.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,23 @@ | ||
import { functions } from "config/firebase.config"; | ||
import { httpsCallable } from "firebase/functions"; | ||
|
||
export function acceptEditorInvite( | ||
homebrewCollectionId: string, | ||
inviteKey: string | ||
): Promise<boolean> { | ||
return new Promise((resolve, reject) => { | ||
const acceptInvite = httpsCallable( | ||
functions, | ||
"addCurrentUserAsHomebrewCampaignEditor" | ||
); | ||
|
||
acceptInvite({ homebrewCollectionId, inviteKey }) | ||
.then((wasSuccessful) => { | ||
resolve(wasSuccessful.data as boolean); | ||
}) | ||
.catch((e) => { | ||
console.error(e); | ||
reject(e); | ||
}); | ||
}); | ||
} |
24 changes: 24 additions & 0 deletions
24
src/api-calls/homebrew/editorFunction/getEditorInviteUrl.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,24 @@ | ||
import { functions } from "config/firebase.config"; | ||
import { httpsCallable } from "firebase/functions"; | ||
|
||
export function getEditorInviteUrl( | ||
homebrewCollectionId: string | ||
): Promise<string | null> { | ||
return new Promise((resolve, reject) => { | ||
const getInviteKey = httpsCallable(functions, "getHomebrewEditorInviteKey"); | ||
|
||
getInviteKey({ homebrewCollectionId }) | ||
.then((inviteKey) => { | ||
if (inviteKey.data) { | ||
resolve(new URL(`/homebrew/invite/${inviteKey.data}`).toString()); | ||
} else { | ||
console.error("NO INVITE KEY RETURNED"); | ||
reject(new Error("No invite key was returned")); | ||
} | ||
}) | ||
.catch((e) => { | ||
console.error(e); | ||
reject(e); | ||
}); | ||
}); | ||
} |
24 changes: 24 additions & 0 deletions
24
src/api-calls/homebrew/editorFunction/getHomebrewCollectionFromInviteUrl.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,24 @@ | ||
import { functions } from "config/firebase.config"; | ||
import { httpsCallable } from "firebase/functions"; | ||
|
||
export function getHomebrewCollectionFromInviteUrl(): Promise<string | null> { | ||
return new Promise((resolve, reject) => { | ||
const inviteKey = location.pathname.substring( | ||
location.pathname.lastIndexOf("/") + 1 | ||
); | ||
|
||
const getHomebrewId = httpsCallable( | ||
functions, | ||
"getHomebrewIdFromInviteKey" | ||
); | ||
|
||
getHomebrewId({ inviteKey }) | ||
.then((homebrewId) => { | ||
return homebrewId.data; | ||
}) | ||
.catch((e) => { | ||
console.error(e); | ||
reject(e); | ||
}); | ||
}); | ||
} |
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