Skip to content

Instantly share code, notes, and snippets.

@prosenjit-manna
Last active July 28, 2022 17:55
Show Gist options
  • Save prosenjit-manna/19e7031894fae4039ac4dec20014a311 to your computer and use it in GitHub Desktop.
Save prosenjit-manna/19e7031894fae4039ac4dec20014a311 to your computer and use it in GitHub Desktop.
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