Skip to content

Commit ef080a8

Browse files
committed
Fully Managed working
1 parent eca2285 commit ef080a8

13 files changed

Lines changed: 83 additions & 51 deletions

File tree

public/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<html lang="en">
33
<head>
44
<meta charset="utf-8" />
5-
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
5+
<link rel="icon" href="%PUBLIC_URL%/purpleLogo.png" />
66
<meta name="viewport" content="width=device-width, initial-scale=1" />
77
<meta name="theme-color" content="#8b15b8" />
88
<meta

public/manifest.json

Lines changed: 0 additions & 20 deletions
This file was deleted.

src/examples/FullyManaged.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ const FullyManaged = () => {
66

77
const onSubmit = async (values) => {
88
await sleep(1000);
9-
// return "We couldn't save your form."";
10-
9+
// Your logic here
1110
console.log('return values', values);
1211
};
1312
return (
@@ -21,7 +20,7 @@ const FullyManaged = () => {
2120
<br />
2221
<div>
2322
<FetchForm
24-
slug='fcd4ca8b-12d4-4b8c-882d-00144d54d02c'
23+
slug='6fa85752-e237-493d-9c63-c441049cb53d'
2524
onSubmit={onSubmit}
2625
/>
2726
</div>

src/lib/exports/components/FetchForm.js

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@ import React, { useEffect, useState } from 'react';
22
import { Form } from 'react-final-form';
33
import useFetchForms from '../hooks/useFetchForms';
44
import FetchFormItem from './form/FetchFormItem';
5-
import { validate } from './form/Validations';
5+
import { validate } from '../scripts/Validations';
66
import '../styles/index.scss';
7-
import useCloudSave from '../hooks/useCloudSave';
87

98
const FetchForm = ({ slug, showFormError, onSubmit }) => {
10-
const [fetchForm, loading, error] = useFetchForms(slug);
11-
const { status, createSubmission } = useCloudSave();
9+
const [fetchForm, loading, error, doCloudSubmit] = useFetchForms(slug);
1210
const [validations, setValidations] = useState({});
1311
const [submitError, setSubmitError] = useState(false);
1412

@@ -43,17 +41,23 @@ const FetchForm = ({ slug, showFormError, onSubmit }) => {
4341
formattedValues[keys[i]] = values[keys[i]];
4442
}
4543
}
44+
console.log(formattedValues);
4645

4746
if (fetchForm.cloudSave) {
48-
await createSubmission(fetchForm.id, formattedValues);
49-
if (status.error) {
50-
return setSubmitError(status.error);
51-
}
52-
}
47+
try {
48+
const isSaved = await doCloudSubmit(fetchForm.id, formattedValues);
49+
if (!isSaved.success) {
50+
throw isSaved.message;
51+
}
5352

54-
const hasError = await onSubmit(formattedValues);
55-
if (hasError) {
56-
setSubmitError(hasError);
53+
const hasError = await onSubmit(formattedValues);
54+
if (hasError) {
55+
throw hasError;
56+
}
57+
} catch (err) {
58+
console.log(err);
59+
setSubmitError(err);
60+
}
5761
}
5862
};
5963

@@ -75,7 +79,6 @@ const FetchForm = ({ slug, showFormError, onSubmit }) => {
7579
initialValues={{}}
7680
validate={(values) => {
7781
const errors = validate(values, validations);
78-
// console.log(errors);
7982
return errors;
8083
}}
8184
render={({ handleSubmit, submitting, invalid }) => (
@@ -92,7 +95,7 @@ const FetchForm = ({ slug, showFormError, onSubmit }) => {
9295
className='fetch-submit-button'
9396
disabled={submitting || invalid}
9497
>
95-
{fetchForm.submitText}
98+
{submitting ? 'Saving...' : fetchForm.submitText}
9699
</button>
97100
</form>
98101
)}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import React from 'react';
2+
3+
const FetchField = ({ label, name, noMargin }) => {
4+
return (
5+
<label
6+
htmlFor={name}
7+
className={`fetch-label ${noMargin ? 'no-margin' : ''}`}
8+
>
9+
{label}
10+
</label>
11+
);
12+
};
13+
14+
export default FetchField;

src/lib/exports/components/form/fields/FetchFormCheckbox.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import FetchLabel from '../elements/FetchLabel';
2+
import FetchLabel from '../FetchLabel';
33

44
const FetchFormCheckbox = ({ label, html }) => {
55
return (

src/lib/exports/components/form/fields/FetchFormInput.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,25 @@
11
import React from 'react';
2-
import FetchLabel from '../elements/FetchLabel';
3-
import { getFormat } from '../Formats';
2+
import FetchLabel from '../FetchLabel';
3+
import { getFormat } from '../../../scripts/Formats';
44
import NumberFormat from 'react-number-format';
55

66
const FetchFormInput = ({ label, html, format }) => {
77
const { numerical, css } = getFormat(format, html.type);
88

9-
if (numerical) {
10-
console.log(html.name, numerical);
11-
}
12-
139
return (
1410
<>
1511
<FetchLabel label={label} name={html.name} />
1612
{numerical ? (
1713
<NumberFormat
1814
{...numerical}
15+
type='text'
1916
name={html.name}
2017
value={html.value}
2118
onBlur={html.onBlur}
2219
onFocus={html.onFocus}
23-
onChange={(value) => html.onChange(value)}
24-
onValueChange={({ formattedValue }) => html.onChange(formattedValue)}
20+
onValueChange={({ floatValue, formattedValue }) => {
21+
html.onChange(html.type === 'number' ? floatValue : formattedValue);
22+
}}
2523
className={`fetch-input ${css}`}
2624
/>
2725
) : (

src/lib/exports/components/form/fields/FetchFormRadio.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useState } from 'react';
2-
import FetchLabel from '../elements/FetchLabel';
2+
import FetchLabel from '../FetchLabel';
33

44
const FetchFormRadio = ({ label, options, fieldName, html }) => {
55
const [checked, setChecked] = useState('');
@@ -12,6 +12,8 @@ const FetchFormRadio = ({ label, options, fieldName, html }) => {
1212
<div className='input-group-field'>
1313
<input
1414
{...html}
15+
value={option.value}
16+
id={option.value}
1517
onClick={(e) => setChecked(e.target.value)}
1618
className={`fetch-radio ${
1719
checked === option.value ? 'checked' : ''

src/lib/exports/components/form/fields/FetchFormSelect.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import FetchLabel from '../elements/FetchLabel';
2+
import FetchLabel from '../FetchLabel';
33

44
const FetchFormSelect = ({ label, options, html }) => {
55
return (

src/lib/exports/components/form/fields/FetchFormTextarea.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import FetchLabel from '../elements/FetchLabel';
2+
import FetchLabel from '../FetchLabel';
33

44
const FetchFormTextarea = ({ label, html }) => {
55
return (

0 commit comments

Comments
 (0)