@beekai/react
Advanced tools
Comparing version 0.0.2 to 0.1.0
# @beekai/react | ||
## 0.1.0 | ||
### Minor Changes | ||
- 1eb3590e7: - add new submissionId prop from useForm hook | ||
## 0.0.2 | ||
@@ -4,0 +10,0 @@ |
{ | ||
"name": "@beekai/react", | ||
"version": "0.0.2", | ||
"version": "0.1.0", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "publishConfig": { |
@@ -10,6 +10,21 @@ <img src="https://www.beekai.com/marketing/og.png" alt="logo" /> | ||
```tsx | ||
const { submit, onSubmit, register, handleSubmit } = useBeikai({ | ||
const { | ||
submit, | ||
onSubmit, | ||
register, | ||
handleSubmit, | ||
submissionId, | ||
formState: { errors } | ||
} = useBeikai({ | ||
formId: 'beekai-form-id' // BEEKAI form applicaiton id | ||
}) | ||
if (submissionId) { | ||
return <p>Thank you! Submission Id is: {submissionId}</p> | ||
} | ||
if (errors?.serverError) { | ||
return <p>Server error and submission failed.</p> | ||
} | ||
// native submit | ||
@@ -16,0 +31,0 @@ return ( |
@@ -0,1 +1,2 @@ | ||
import * as React from 'react'; | ||
import { | ||
@@ -21,4 +22,6 @@ useForm as hookFormUseForm, | ||
submit: SubmitHandler<TFieldValues>; | ||
submissionId: string; | ||
onSubmit: (e: React.BaseSyntheticEvent) => void; | ||
} { | ||
const [submissionId, setSubmissionId] = React.useState(''); | ||
const { formId, ...rest } = props; | ||
@@ -32,3 +35,3 @@ const methods = hookFormUseForm<TFieldValues, TContext>(rest); | ||
try { | ||
const result = await fetch('https://beekai.com/api/v1/submit', { | ||
const response = await fetch('https://beekai.com/api/v1/submit', { | ||
method: 'POST', | ||
@@ -39,6 +42,8 @@ body: JSON.stringify({ form_id: props.formId, data }), | ||
if (result.status !== 200) { | ||
if (response.status !== 200) { | ||
const data = await response.json(); | ||
setSubmissionId(data.id); | ||
methods.setError('serverError' as FieldPath<TFieldValues>, { | ||
type: 'server', | ||
message: `Request has failed with status code ${result.status}`, | ||
message: `Request has failed with status code ${response.status}`, | ||
}); | ||
@@ -59,2 +64,3 @@ } | ||
submit, | ||
submissionId, | ||
onSubmit: (e) => { | ||
@@ -61,0 +67,0 @@ methods.clearErrors(); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6636
223
45