-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #142 from ThatConference/feat/member-network-sharing
feat: member–member sharing of shared profile data
- Loading branch information
Showing
18 changed files
with
1,059 additions
and
15 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
183 changes: 183 additions & 0 deletions
183
src/_dataSources/api.that.tech/memberShareWith/mutations.js
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,183 @@ | ||
import gFetch from '$lib/gfetch'; | ||
import { log } from '../utilities/error'; | ||
|
||
const secureProfileFields = ` | ||
fragment secureProfileFields on SecureProfile { | ||
... on PrivateProfile { | ||
__typename | ||
id | ||
firstName | ||
lastInitial | ||
} | ||
... on PublicProfile { | ||
__typename | ||
id | ||
firstName | ||
lastName | ||
profileSlug | ||
} | ||
} | ||
`; | ||
export const MUTATION_ADD_SHARE_WITH_BY_PIN = ` | ||
${secureProfileFields} | ||
mutation addShareWithPin($shareWith: ShareWithByPinInput!) { | ||
members { | ||
network { | ||
add { | ||
pin(shareWith: $shareWith) { | ||
__typename | ||
isSuccess | ||
message | ||
sharedWith { | ||
__typename | ||
createdAt | ||
lastUpdatedAt | ||
notes | ||
sharingWithProfile { | ||
...secureProfileFields | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
`; | ||
export const MUTATION_ADD_SHARE_WITH_PROFILE = ` | ||
${secureProfileFields} | ||
mutation addShareWithProfile($shareWith: ShareWithByProfileInput!) { | ||
members { | ||
network { | ||
add { | ||
profile(shareWith: $shareWith) { | ||
__typename | ||
isSuccess | ||
message | ||
sharedWith { | ||
__typename | ||
createdAt | ||
lastUpdatedAt | ||
notes | ||
sharingWithProfile { | ||
...secureProfileFields | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
`; | ||
export const MUTATION_UPDATE_SHARE_WITH = ` | ||
${secureProfileFields} | ||
mutation updateShareWith($memberId: ID!, $shareWithData: ShareWithUpdateInput!) { | ||
members { | ||
network { | ||
sharingWith (sharedWithId: $memberId) { | ||
update(shareWith: $shareWithData) { | ||
notes | ||
sharingWithProfile { | ||
...secureProfileFields | ||
} | ||
createdAt | ||
lastUpdatedAt | ||
} | ||
} | ||
} | ||
} | ||
} | ||
`; | ||
export const MUTATION_REMOVE_SHARE = ` | ||
mutation removeShareWith($memberId: ID!) { | ||
members { | ||
network { | ||
sharingWith (sharedWithId: $memberId) { | ||
remove | ||
} | ||
} | ||
} | ||
} | ||
`; | ||
|
||
export default (fetch) => { | ||
const client = fetch ? gFetch(fetch) : gFetch(); | ||
|
||
function shareWithByPin(shareWith) { | ||
const variables = { shareWith }; | ||
return client | ||
.mutation({ mutation: MUTATION_ADD_SHARE_WITH_BY_PIN, variables }) | ||
.then(({ data, errors }) => { | ||
if (errors) { | ||
log({ errors, tag: 'MUTATION_ADD_SHARE_WITH' }); | ||
throw new Error('An error occurred while sharing your information'); | ||
} | ||
|
||
return data.members.network.add.pin; | ||
}); | ||
} | ||
|
||
function shareWithByProfile(shareWith) { | ||
const { id, profileSlug, notes } = shareWith; | ||
const variables = { | ||
shareWith: { | ||
shareWithMember: { | ||
id: id ?? null, | ||
slug: profileSlug ?? null | ||
}, | ||
notes: notes ?? '' | ||
} | ||
}; | ||
|
||
return client | ||
.mutation({ mutation: MUTATION_ADD_SHARE_WITH_PROFILE, variables }) | ||
.then(({ data, errors }) => { | ||
if (errors) { | ||
log({ errors, tag: 'MUTATION_ADD_SHARE_WITH_PROFILE' }); | ||
throw new Error('An error occurred while sharing your information'); | ||
} | ||
|
||
return data.members.network.add.profile; | ||
}); | ||
} | ||
|
||
function updateShareWith(memberId, notes = '') { | ||
const variables = { | ||
memberId, | ||
shareWithData: { | ||
notes | ||
} | ||
}; | ||
|
||
return client | ||
.mutation({ mutation: MUTATION_UPDATE_SHARE_WITH, variables }) | ||
.then(({ data, errors }) => { | ||
if (errors) { | ||
log({ errors, tag: 'MUTATION_UPDATE_SHARE_WITH' }); | ||
throw new Error('An error occurred while updating share information'); | ||
} | ||
|
||
return data.members.network.sharingWith.update; | ||
}); | ||
} | ||
|
||
function removeShareWith(memberId) { | ||
const variables = { memberId }; | ||
return client | ||
.mutation({ mutation: MUTATION_REMOVE_SHARE, variables }) | ||
.then(({ data, errors }) => { | ||
if (errors) { | ||
log({ errors, tag: 'MUTATION_REMOVE_SHARE' }); | ||
throw new Error('An error occurred removing the share'); | ||
} | ||
|
||
return data.members.network.sharingWith.remove; | ||
}); | ||
} | ||
|
||
return { | ||
shareWithByPin, | ||
shareWithByProfile, | ||
updateShareWith, | ||
removeShareWith | ||
}; | ||
}; |
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,94 @@ | ||
import gFetch from '$lib/gfetch'; | ||
|
||
import { log } from '../utilities/error'; | ||
|
||
const secureProfileFields = ` | ||
fragment secureProfileFields on SecureProfile { | ||
... on PrivateProfile { | ||
__typename | ||
id | ||
firstName | ||
lastInitial | ||
} | ||
... on PublicProfile { | ||
__typename | ||
id | ||
firstName | ||
lastName | ||
profileImage | ||
} | ||
} | ||
`; | ||
|
||
export const QUERY_ME_SHARING_WITH = ` | ||
${secureProfileFields} | ||
query meSharingWith { | ||
members { | ||
network { | ||
sharedByMe { | ||
notes | ||
sharingWithProfile { | ||
...secureProfileFields | ||
} | ||
} | ||
} | ||
} | ||
} | ||
`; | ||
|
||
export const QUERY_SHARING_WITH_ME = ` | ||
${secureProfileFields} | ||
query sharingWithMe { | ||
members { | ||
network { | ||
sharedWithMe { | ||
sharedWithMeProfile { | ||
...secureProfileFields | ||
} | ||
sharedWithMeSharedProfile { | ||
__typename | ||
firstName | ||
lastName | ||
company | ||
phone | ||
city | ||
state | ||
country | ||
} | ||
createdAt | ||
} | ||
} | ||
} | ||
} | ||
`; | ||
|
||
export default (fetch) => { | ||
const client = fetch ? gFetch(fetch) : gFetch(); | ||
|
||
const getMeSharingWith = () => { | ||
return client | ||
.secureQuery({ query: QUERY_ME_SHARING_WITH, variables: {} }) | ||
.then(({ data, errors }) => { | ||
if (errors) log({ errors, tag: 'QUERY_SHARING_WITH_ME' }); | ||
|
||
return data.members.network.sharedByMe; | ||
}); | ||
}; | ||
|
||
const getSharingWithMe = () => { | ||
return client | ||
.secureQuery({ query: QUERY_SHARING_WITH_ME, variables: {} }) | ||
.then(({ data, errors }) => { | ||
if (errors) log({ errors, tag: 'QUERY_SHARING_WITH_ME' }); | ||
|
||
return data.members.network.sharedWithMe; | ||
}); | ||
}; | ||
|
||
return { | ||
getMeSharingWith, | ||
getSharingWithMe | ||
}; | ||
}; |
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,14 @@ | ||
<div | ||
class="focus:bg-thatBlue-300focus:text-white whitespace-nowrap rounded-md border-2 | ||
border-thatBlue-500 bg-thatBlue-500 | ||
px-8 py-2 text-base font-medium | ||
leading-6 text-white | ||
shadow transition duration-150 ease-in-out | ||
hover:border-thatBlue-300 | ||
hover:bg-thatBlue-300 hover:text-white | ||
md:px-10 md:text-lg | ||
"> | ||
<div class="flex h-full w-full items-center justify-center"> | ||
<slot /> | ||
</div> | ||
</div> |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { z } from 'zod'; | ||
|
||
export default z.object({ | ||
id: z.string().trim(), | ||
notes: z.string().trim().max(1000).nullable().optional() | ||
}); |
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.