react-google-forms-hooks
Advanced tools
Comparing version 1.0.2 to 1.0.3
import { GoogleForm, UseGoogleFormReturn } from '../types'; | ||
export declare const GOOGLE_FORMS_URL = "https://docs.google.com/forms/d"; | ||
export declare const formatQuestionName: (id: string) => string; | ||
@@ -3,0 +4,0 @@ export declare const useGoogleForm: ({ form }: { |
export * from './hooks'; | ||
export * from './scripts/googleFormsToJson'; | ||
export * from './scripts/submitToGoogleForms'; | ||
export * from './types'; |
@@ -662,5 +662,27 @@ function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } | ||
var submitToGoogleForms = function submitToGoogleForms(form, formData) { | ||
try { | ||
var fields = {}; | ||
Object.keys(formData).forEach(function (key) { | ||
fields[formatQuestionName(key)] = formData[key]; | ||
}); | ||
var params = queryString.stringify(fields, { | ||
skipNull: true, | ||
skipEmptyString: true | ||
}); | ||
return Promise.resolve(axios.get(GOOGLE_FORMS_URL + "/" + form.action + "/formResponse?" + params + "&submit=Submit", { | ||
headers: { | ||
'Content-Type': 'application/x-www-form-urlencoded' | ||
} | ||
})); | ||
} catch (e) { | ||
return Promise.reject(e); | ||
} | ||
}; | ||
exports.GOOGLE_FORMS_URL = GOOGLE_FORMS_URL; | ||
exports.GoogleFormProvider = GoogleFormProvider; | ||
exports.formatQuestionName = formatQuestionName; | ||
exports.googleFormsToJson = googleFormsToJson; | ||
exports.submitToGoogleForms = submitToGoogleForms; | ||
exports.useCheckboxGridInput = useCheckboxGridInput; | ||
@@ -667,0 +689,0 @@ exports.useCheckboxInput = useCheckboxInput; |
@@ -660,3 +660,23 @@ import { useForm } from 'react-hook-form'; | ||
export { GoogleFormProvider, formatQuestionName, googleFormsToJson, useCheckboxGridInput, useCheckboxInput, useDropdownInput, useGoogleForm, useGoogleFormContext, useLinearInput, useLongAnswerInput, useRadioGridInput, useRadioInput, useShortAnswerInput }; | ||
var submitToGoogleForms = function submitToGoogleForms(form, formData) { | ||
try { | ||
var fields = {}; | ||
Object.keys(formData).forEach(function (key) { | ||
fields[formatQuestionName(key)] = formData[key]; | ||
}); | ||
var params = queryString.stringify(fields, { | ||
skipNull: true, | ||
skipEmptyString: true | ||
}); | ||
return Promise.resolve(axios.get(GOOGLE_FORMS_URL + "/" + form.action + "/formResponse?" + params + "&submit=Submit", { | ||
headers: { | ||
'Content-Type': 'application/x-www-form-urlencoded' | ||
} | ||
})); | ||
} catch (e) { | ||
return Promise.reject(e); | ||
} | ||
}; | ||
export { GOOGLE_FORMS_URL, GoogleFormProvider, formatQuestionName, googleFormsToJson, submitToGoogleForms, useCheckboxGridInput, useCheckboxInput, useDropdownInput, useGoogleForm, useGoogleFormContext, useLinearInput, useLongAnswerInput, useRadioGridInput, useRadioInput, useShortAnswerInput }; | ||
//# sourceMappingURL=index.modern.js.map |
{ | ||
"name": "react-google-forms-hooks", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "Library to create forms using React backed by Google Forms.", | ||
@@ -5,0 +5,0 @@ "author": "francisconeves97", |
@@ -86,2 +86,3 @@ # React Google Forms Hooks | ||
- Right now there is no observability on errors when submitting a form. See this [comment on the code](https://github.com/francisconeves97/react-google-forms-hooks/blob/ca5018e578cfb0e230f9be58dfeee4117db28160/src/hooks/useGoogleForm.ts#L61-L65). | ||
- You can use the `submitToGoogleForm` export to create a server to handle form submissions. This way you can mitigate the CORS problem. | ||
- No support for multi page, sections, images and other Google Forms functionalities. However you can build your React form with multiple pages, by saving the `data` from `handleSubmit` and only `submitToGoogleForms` on the last page. | ||
@@ -88,0 +89,0 @@ - The list of supported inputs doesn't feature every input from Google Forms. Supported inputs: Short Answer, Long Answer, Checkbox, Radio, Dropdown, Linear, Radio Grid, Checkbox Grid |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
171499
38
1334
102