-
Notifications
You must be signed in to change notification settings - Fork 344
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
56 additions
and
43 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { Button, Container, Typography } from '@mui/material'; | ||
import React, { useState } from 'react'; | ||
import { giftClientWithoutCache } from '@site/src/api/client'; | ||
import { useRequireLogin } from '@site/src/context/user'; | ||
|
||
export function ClaimCredits () { | ||
const [email, setEmail] = useState(); | ||
const requireLogin = useRequireLogin(); | ||
const handleClick = async () => { | ||
let accessToken: string; | ||
try { | ||
accessToken = await requireLogin('gift'); | ||
} catch (e) { | ||
console.error('Failed to get the access token.', e); | ||
return; | ||
} | ||
|
||
const res = await giftClientWithoutCache.post<any, any>( | ||
'/api/v1/credits/claim', | ||
{}, | ||
{ | ||
withCredentials: true, | ||
oToken: accessToken, | ||
}, | ||
); | ||
|
||
setEmail(res?.metadata?.email); | ||
}; | ||
|
||
return (<> | ||
<Container maxWidth="sm" sx={{ pt: 6, pb: 12 }}> | ||
<Typography variant="h1" mb={4}> | ||
My Gift | ||
</Typography> | ||
<Button | ||
variant="contained" | ||
onClick={() => { | ||
handleClick().catch((err) => { | ||
console.error(err); | ||
alert('Failed to claim your gift'); | ||
}); | ||
}}> | ||
Claim | ||
</Button> | ||
<p>{email}</p> | ||
</Container> | ||
</>); | ||
} |
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 |
---|---|---|
@@ -1,47 +1,11 @@ | ||
import CustomPage from '@site/src/theme/CustomPage'; | ||
import React, { useState } from 'react'; | ||
import { Button, Container, Typography } from '@mui/material'; | ||
import { useAuth0 } from '@auth0/auth0-react'; | ||
import React from 'react'; | ||
import { ClaimCredits } from '@site/src/pages/gift/_components/ClaimCredits'; | ||
|
||
export default function Page () { | ||
const [email, setEmail] = useState(); | ||
const { isLoading: userValidating, isAuthenticated: userValidated } = useAuth0(); | ||
|
||
const handleClick = async () => { | ||
if (userValidated) { | ||
const res = await fetch('https:/gift.ossinsight.io/api/v1/credits/claim', { | ||
method: 'POST', | ||
}); | ||
if (!res.ok) { | ||
alert('Failed to claim your gift'); | ||
return; | ||
} | ||
const data = await res.json(); | ||
setEmail(data?.metadata?.email); | ||
} else { | ||
alert('Please login to claim your gift'); | ||
} | ||
}; | ||
|
||
return ( | ||
<CustomPage title="Gift for OSS Contributors"> | ||
<Container maxWidth="sm" sx={{ pt: 6, pb: 12 }}> | ||
<Typography variant="h1" mb={4}> | ||
My Gift | ||
</Typography> | ||
<Button | ||
disabled={userValidating} | ||
variant="contained" | ||
onClick={() => { | ||
handleClick().catch((err) => { | ||
console.error(err); | ||
alert('Failed to claim your gift'); | ||
}); | ||
}}> | ||
Claim | ||
</Button> | ||
<p>{email}</p> | ||
</Container> | ||
<ClaimCredits/> | ||
</CustomPage> | ||
); | ||
} |