-
Notifications
You must be signed in to change notification settings - Fork 17
Feature/redeem endpoint #1554
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Feature/redeem endpoint #1554
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
472aaca
package-lock.json
sunilsabatp 520bc19
change the redeem endpoint in profile
sunilsabatp 8a43ba0
fix the error message for redeem code
sunilsabatp fa20e79
fix codefactor error
sunilsabatp 51f1942
removed unused entities
sunilsabatp 0aad0ae
fix client-side exception issue
sunilsabatp b11c602
fix the button and validation for redeem modal
sunilsabatp f437e97
changed name of validate button
sunilsabatp 9719b4e
pull the latest changes from remote
sunilsabatp 50140c4
fix redeem modal
sunilsabatp 78687a8
added button for successful redeem modal
sunilsabatp 893b853
Merge branch 'develop' of https://github.com/Plant-for-the-Planet-org…
sunilsabatp 24b3e99
merged develop
sunilsabatp 7684044
fix codefactor suggested error
sunilsabatp 9a1a8e3
defined type for data
sunilsabatp bb2ecad
defined type for userProfile
sunilsabatp da4c1c6
fix the redeem code through route
sunilsabatp 5afb945
removed loaduser from redeemmodal
sunilsabatp a1d5342
clean up code
sunilsabatp 81bfe18
fixed the structure of redeem modal
sunilsabatp 8ecddb1
refactor: minor cleanup
mohitb35 d15a3e9
fix structure of modal
sunilsabatp a2a8aac
cleaned up the repetitive code
sunilsabatp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -13,6 +13,7 @@ import { UserPropsContext } from '../../../src/features/common/Layout/UserPropsC | |
| import { ErrorHandlingContext } from '../../../src/features/common/Layout/ErrorHandlingContext'; | ||
| import ShareOptions from '../../../src/features/common/ShareOptions/ShareOptions'; | ||
| import { styled } from '@mui/material'; | ||
| import CancelIcon from '../../../public/assets/images/icons/CancelIcon'; | ||
|
|
||
| const { useTranslation } = i18next; | ||
|
|
||
|
|
@@ -87,27 +88,26 @@ function ClaimDonation({}: Props): ReactElement { | |
| } | ||
| }, [router]); | ||
|
|
||
| async function validateCode(code: any, type: any) { | ||
| async function redeemCode(code: string) { | ||
| setIsUploadingData(true); | ||
| const submitData = { | ||
| type: type, | ||
| // type: type, | ||
| code: code, | ||
| }; | ||
| if (contextLoaded && user) { | ||
| const userLang = localStorage.getItem('language') || 'en'; | ||
| postAuthenticatedRequest( | ||
| `/api/v1.3/${userLang}/validateCode`, | ||
| `/app/redeem`, | ||
| submitData, | ||
| token, | ||
| handleError | ||
| ).then((res) => { | ||
| if (res.code === 401) { | ||
| setErrorMessage(res.message); | ||
| if (res.error_code === 'already_redeemed') { | ||
| setErrorMessage(t('redeem:alreadyRedeemed')); | ||
| setIsUploadingData(false); | ||
| } else if (res.status === 'error') { | ||
| setErrorMessage(res.errorText || t('me:wentWrong')); | ||
| } else if (res.error_code === 'invalid_code') { | ||
| setErrorMessage(t('redeem:invalidCode')); | ||
| setIsUploadingData(false); | ||
| } else if (res.status === 'success') { | ||
| } else if (res.status === 'redeemed') { | ||
| setCodeValidated(true); | ||
| setValidCodeData(res); | ||
| setIsUploadingData(false); | ||
|
|
@@ -125,8 +125,8 @@ function ClaimDonation({}: Props): ReactElement { | |
| // From here user can go back to home by clicking X | ||
| if (contextLoaded && user) { | ||
| // validate code | ||
| if (routerReady && code && type) { | ||
| validateCode(code, type); | ||
| if (routerReady && code) { | ||
| redeemCode(code); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -145,34 +145,34 @@ function ClaimDonation({}: Props): ReactElement { | |
| } | ||
| }, [contextLoaded, user, code]); | ||
|
|
||
| async function redeemCode(code: any, type: any) { | ||
| setIsUploadingData(true); | ||
| const submitData = { | ||
| type: type, | ||
| code: code, | ||
| }; | ||
| if (contextLoaded && user) { | ||
| const userLang = localStorage.getItem('language') || 'en'; | ||
| postAuthenticatedRequest( | ||
| `/api/v1.3/${userLang}/convertCode`, | ||
| submitData, | ||
| token, | ||
| handleError | ||
| ).then((res) => { | ||
| if (res.code === 401) { | ||
| setErrorMessage(res.message); | ||
| setIsUploadingData(false); | ||
| } else if (!res.response || res.response.status === 'error') { | ||
| setErrorMessage(res.errorText || t('me:wentWrong')); | ||
| setIsUploadingData(false); | ||
| } else if (res.response.status === 'success') { | ||
| setCodeRedeemed(true); | ||
| setIsUploadingData(false); | ||
| setCodeValidated(false); | ||
| } | ||
| }); | ||
| } | ||
| } | ||
| // async function redeemCode(code: any, type: any) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can remove unused code. We have git if we want to retrieve it again. |
||
| // setIsUploadingData(true); | ||
| // const submitData = { | ||
| // type: type, | ||
| // code: code, | ||
| // }; | ||
| // if (contextLoaded && user) { | ||
| // const userLang = localStorage.getItem('language') || 'en'; | ||
| // postAuthenticatedRequest( | ||
| // `/api/v1.3/${userLang}/convertCode`, | ||
| // submitData, | ||
| // token, | ||
| // handleError | ||
| // ).then((res) => { | ||
| // if (res.code === 401) { | ||
| // setErrorMessage(res.message); | ||
| // setIsUploadingData(false); | ||
| // } else if (!res.response || res.response.status === 'error') { | ||
| // setErrorMessage(res.errorText || t('me:wentWrong')); | ||
| // setIsUploadingData(false); | ||
| // } else if (res.response.status === 'success') { | ||
| // setCodeRedeemed(true); | ||
| // setIsUploadingData(false); | ||
| // setCodeValidated(false); | ||
| // } | ||
| // }); | ||
| // } | ||
| // } | ||
|
|
||
|
sunilsabatp marked this conversation as resolved.
|
||
| const closeRedeem = () => { | ||
| setCodeValidated(false); | ||
|
|
@@ -288,61 +288,58 @@ function ClaimDonation({}: Props): ReactElement { | |
| <div className={styles.modal}> | ||
| {codeValidated && validCodeData ? ( | ||
| <> | ||
| {errorMessage && ( | ||
| <span className={styles.formErrors}>{errorMessage}</span> | ||
| )} | ||
| <div style={{ position: 'relative', left: '108px' }}> | ||
| <button className={styles.crossButton}> | ||
| <CancelIcon /> | ||
| </button> | ||
| </div> | ||
|
|
||
| <div className={styles.codeTreeCount}> | ||
| {getFormattedNumber( | ||
| i18n.language, | ||
| Number(validCodeData.treeCount) | ||
| Number(validCodeData.units) | ||
| )} | ||
| <span> | ||
| {t('common:tree', { | ||
| count: Number(validCodeData.treeCount), | ||
| count: Number(validCodeData.units), | ||
| })} | ||
| </span> | ||
| </div> | ||
|
|
||
| {validCodeData.tpos?.length > 0 && ( | ||
| <div className={styles.plantedBy}> | ||
| <span>{t('common:plantedBy')}</span> | ||
| <p>{validCodeData.tpos[0].tpoName}</p> | ||
| </div> | ||
| )} | ||
|
|
||
| <div | ||
| onClick={() => redeemCode(code, type)} | ||
| className="primaryButton" | ||
| style={{ maxWidth: '200px', marginTop: '24px' }} | ||
| > | ||
| {isUploadingData ? ( | ||
| <div className={styles.spinner}></div> | ||
| ) : ( | ||
| t('redeem:addToMyTrees') | ||
| )} | ||
| <div className={styles.codeTreeCount}> | ||
| <span>{t('redeem:successfullyRedeemed')}</span> | ||
| </div> | ||
| </> | ||
| ) : ( | ||
| <> | ||
| <div> | ||
| {t('redeem:validating')} {code} | ||
| <div style={{ position: 'relative', left: '108px' }}> | ||
| <button className={styles.crossButton} onClick={closeRedeem}> | ||
| <CancelIcon /> | ||
| </button> | ||
| </div> | ||
| {errorMessage ? ( | ||
| <div style={{ fontWeight: 'bold' }}>{code}</div> | ||
| ) : ( | ||
| <div style={{ fontWeight: 'bold' }}> | ||
| {t('redeem:redeeming')} {code} | ||
| </div> | ||
| )} | ||
|
|
||
| {errorMessage && ( | ||
| {errorMessage ? ( | ||
| <span className={styles.formErrors}>{errorMessage}</span> | ||
| ) : ( | ||
| <div | ||
| onClick={() => redeemCode(code)} | ||
| className="primaryButton" | ||
| style={{ maxWidth: '200px', marginTop: '24px' }} | ||
| > | ||
| {isUploadingData ? ( | ||
| <div className={styles.spinner}></div> | ||
| ) : ( | ||
| t('redeem:redeemCode') | ||
| )} | ||
| </div> | ||
| )} | ||
| <div | ||
| onClick={() => validateCode(code, type)} | ||
| className="primaryButton" | ||
| style={{ maxWidth: '200px', marginTop: '24px' }} | ||
| > | ||
| {isUploadingData ? ( | ||
| <div className={styles.spinner}></div> | ||
| ) : ( | ||
| t('redeem:validateCode') | ||
| )} | ||
| </div> | ||
| </> | ||
| )} | ||
| </div> | ||
|
|
||
This file contains hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove commented code.