Last active
July 28, 2022 17:55
-
-
Save prosenjit-manna/19e7031894fae4039ac4dec20014a311 to your computer and use it in GitHub Desktop.
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
const verifyPurchase = async (value: string, values: yup.TestContext<any>) => { | |
try { | |
await ticketApi.getPurchaseCode({ value: value }); | |
return true; | |
} catch (e) { | |
values.createError({ path: 'purchase_code' }); | |
return false; | |
} | |
}; | |
const debounceVerifyPurchase = debounce(verifyPurchase, 1500); | |
const schema = yup.object({ | |
purchase_code: yup | |
.string() | |
.required('Purchase code required') | |
.test('verified', 'Code not verified', async (value, values) => { | |
const verified = await debounceVerifyPurchase(value as string, values); | |
return verified as boolean; | |
}), | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment