-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: update post page to show data if token
- Loading branch information
Showing
6 changed files
with
78 additions
and
13 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
web-components/src/components/cards/PostCard/PostCard.constants.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 @@ | ||
export const SIGNED_BY = 'Signed by'; |
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
46 changes: 46 additions & 0 deletions
46
web-marketplace/src/pages/Post/hooks/useSharePrivateLink.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,46 @@ | ||
import { useCallback } from 'react'; | ||
import { useQuery } from '@tanstack/react-query'; | ||
import { useSetAtom } from 'jotai'; | ||
import { postData } from 'utils/fetch/postData'; | ||
|
||
import { COPY_SUCCESS } from 'web-components/src/components/organisms/ProfileHeader/ProfileHeader.constants'; | ||
import copyTextToClipboard from 'web-components/src/utils/copy'; | ||
|
||
import { apiUri } from 'lib/apiUri'; | ||
import { bannerTextAtom } from 'lib/atoms/banner.atoms'; | ||
import { errorBannerTextAtom } from 'lib/atoms/error.atoms'; | ||
import { useRetryCsrfRequest } from 'lib/errors/hooks/useRetryCsrfRequest'; | ||
import { getCsrfTokenQuery } from 'lib/queries/react-query/registry-server/getCsrfTokenQuery/getCsrfTokenQuery'; | ||
|
||
type Params = { | ||
iri?: string; | ||
}; | ||
|
||
export const useSharePrivateLink = ({ iri }: Params) => { | ||
const retryCsrfRequest = useRetryCsrfRequest(); | ||
const { data: token } = useQuery(getCsrfTokenQuery({})); | ||
const setErrorBannerTextAtom = useSetAtom(errorBannerTextAtom); | ||
const setBannerText = useSetAtom(bannerTextAtom); | ||
|
||
const sharePrivateLink = useCallback(async () => { | ||
if (token && iri) { | ||
try { | ||
await postData({ | ||
url: `${apiUri}/marketplace/v1/posts/${iri}/token`, | ||
token, | ||
retryCsrfRequest, | ||
onSuccess: async response => { | ||
const token = response.token; | ||
await copyTextToClipboard( | ||
`${window.location.origin}/post/${iri}?token=${token}`, | ||
); | ||
setBannerText(COPY_SUCCESS); | ||
}, | ||
}); | ||
} catch (e) { | ||
setErrorBannerTextAtom(String(e)); | ||
} | ||
} | ||
}, [iri, retryCsrfRequest, setBannerText, setErrorBannerTextAtom, token]); | ||
return sharePrivateLink; | ||
}; |