Skip to content

Commit e9146b8

Browse files
committed
feat: signup form submits data from module form fields
1 parent 55ec848 commit e9146b8

File tree

2 files changed

+37
-75
lines changed

2 files changed

+37
-75
lines changed

components/signup-card.vue

+37-61
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@
5555
</template>
5656

5757
<script setup>
58-
// const config = useRuntimeConfig()
59-
// const buttonStore = useZeroButtonStore()
58+
const config = useRuntimeConfig()
59+
const buttonStore = useZeroButtonStore()
6060
// ======================================================================= Props
6161
const props = defineProps({
6262
signupCard: {
@@ -69,18 +69,6 @@ const props = defineProps({
6969
// ======================================================================== Data
7070
const formSubmitted = ref(false)
7171
const submitError = ref(false)
72-
// const fieldError = ref({
73-
// firstName: false,
74-
// lastName: false,
75-
// email: false,
76-
// organization: false,
77-
// country: false
78-
// })
79-
// const firstName = ref(false)
80-
// const lastName = ref(false)
81-
// const email = ref(false)
82-
// const organization = ref(false)
83-
// const country = ref(false)
8472
8573
// ==================================================================== Computed
8674
const title = computed(() => props.signupCard.title )
@@ -97,76 +85,64 @@ const cardStyles = computed(() => {
9785
})
9886
9987
const formId = computed(() => props.signupCard.signup_form_id)
100-
10188
const firstNameFieldScaffold = computed(() => props.signupCard.signup_form.first_name )
102-
10389
const lastNameFieldScaffold = computed(() => props.signupCard.signup_form.last_name )
104-
10590
const emailFieldScaffold = computed(() => props.signupCard.signup_form.email )
106-
10791
const orgFieldScaffold = computed(() => props.signupCard.signup_form.org )
108-
10992
const countryFieldScaffold = computed(() => props.signupCard.signup_form.country )
11093
11194
const submitButtonLabel = computed(() => formSubmitted.value ? 'Success' : 'Register' )
11295
113-
// ===================================================================== Hooks
114-
onMounted(() => {
115-
console.log('mounted')
116-
})
117-
11896
// ===================================================================== Methdos
11997
/**
12098
* @method validateFormValues
12199
*/
122100
const validateFormValues = async () => {
123101
const pass = await useValidateForm(formId.value)
124-
console.log('pass ', pass)
125102
if (pass) {
126-
const formValues = useGetFormFields(formId.value)
127-
console.log('formValues ', formValues)
103+
const formFields = useGetFormFields(formId.value)
104+
const formValues = {}
105+
formFields.forEach((field) => {
106+
if (field.scaffold.type === 'input') {
107+
formValues[field.scaffold.slug] = field.value.trim()
108+
}
109+
if (field.scaffold.type === 'select') {
110+
formValues[field.scaffold.slug] = field.scaffold.options[field.value[0]].label
111+
}
112+
})
113+
return formValues
114+
} else {
115+
return false
128116
}
129117
}
130118
/**
131119
* @method submitForm
132120
*/
133121
const submitForm = async () => {
134-
console.log('submmitting form')
135122
if (formSubmitted.value) { return }
136123
if (submitError.value) { submitError.value = false }
137-
const values = await validateFormValues()
138-
console.log('values ', values)
139-
// if (validateFormValues()) {
140-
// const body = {
141-
// records: [
142-
// {
143-
// fields: {
144-
// email: email.value.trim(),
145-
// firstname: firstName.value.trim(),
146-
// lastname: lastName.value.trim(),
147-
// company: organization.value.trim(),
148-
// country: country.value.label
149-
// }
150-
// }
151-
// ]
152-
// }
153-
// const headers = {
154-
// 'Content-Type': 'application/json',
155-
// 'Authorization': `Bearer ${config.public.airtableToken}`
156-
// }
157-
158-
// await $fetch('https://api.airtable.com/v0/apphbQmrNLNNXiaqG/tblDUSr66nczukX9Y', {
159-
// method: 'POST',
160-
// body,
161-
// headers
162-
// }).then(() => {
163-
// formSubmitted.value = true
164-
// return
165-
// }).catch(() => {
166-
// submitError.value = true
167-
// })
168-
// }
169-
// buttonStore.set({id: 'signup-card-form', loading: false})
124+
const fields = await validateFormValues()
125+
if (fields) {
126+
const body = {
127+
records: [{ fields }]
128+
}
129+
const headers = {
130+
'Content-Type': 'application/json',
131+
'Authorization': `Bearer ${config.public.airtableToken}`
132+
}
133+
134+
await $fetch('https://api.airtable.com/v0/apphbQmrNLNNXiaqG/tblDUSr66nczukX9Y', {
135+
method: 'POST',
136+
body,
137+
headers
138+
}).then(() => {
139+
formSubmitted.value = true
140+
return
141+
}).catch(() => {
142+
submitError.value = true
143+
})
144+
}
145+
buttonStore.setButton({id: 'signup-card-form', loading: false})
170146
}
171147
</script>
172148

pages/signup.vue

-14
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,7 @@ definePageMeta({
3434
3535
// ======================================================================== Data
3636
const pageContent = Content.page_content
37-
// const generalStore = useGeneralStore()
38-
// const { data } = await useAsyncData('signup', async () => {
39-
// return queryContent('core').find()
40-
// })
4137
42-
// ==================================================================== Watchers
43-
// watch(data, async (val) => {
44-
// await generalStore.getBaseData('general')
45-
// await generalStore.getBaseData({ key: 'signup', data: val.find((item) => item._file === 'core/signup.json') })
46-
// }, { immediate: true })
47-
48-
// ==================================================================== Computed
49-
// const content = computed(() => {
50-
// return generalStore.siteContent?.signup?.page_content
51-
// })
5238
</script>
5339

5440
<style lang="scss" scoped>

0 commit comments

Comments
 (0)