Skip to content

Commit

Permalink
Merge pull request #44 from longbridgeapp/main
Browse files Browse the repository at this point in the history
feat: 通过 webhook 提交表单到飞书
  • Loading branch information
zengzijian authored Oct 16, 2024
2 parents 55572f3 + 3e46b89 commit 8eac064
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 13 deletions.
18 changes: 5 additions & 13 deletions features/contact-form/index.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
import { Form, Tabs, Input, Button, DatePicker, TimePicker, Checkbox, message } from 'antd'
import { createClient } from '@supabase/supabase-js'
import styles from './index.module.scss'
import { useMemo, useState } from 'react'
import { useTranslation } from 'next-i18next'
// @ts-ignore
import debounce from 'lodash/debounce'

const supabaseUrl = 'https://fttapltgubuovrbvgvjg.supabase.co'
const supabaseKey =
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImZ0dGFwbHRndWJ1b3ZyYnZndmpnIiwicm9sZSI6ImFub24iLCJpYXQiOjE3MjQ5MjE0MDAsImV4cCI6MjA0MDQ5NzQwMH0.5lpEBaKxHXoQfE-rJksy9Et-e5A3EXUzkTc52lGpAyc'
const supabaseClient = createClient(supabaseUrl, supabaseKey)
import { submitContactUsForm } from '@/services'

type IPrivacyPolicy = { [key: string]: string }

Expand All @@ -32,7 +27,6 @@ const ContactForm = () => {
}

const handleSubmit = () => {
if (!supabaseClient) return
if (isLoading) return

const {
Expand Down Expand Up @@ -73,18 +67,16 @@ const ContactForm = () => {
} else {
delete insertData.enquiry_type
delete insertData.description
const { time } = insertData
const { date, time } = insertData
insertData.date = date.format('YYYY-MM-DD')
insertData.time = time.format('HH:mm')
}
const { data, error } = await supabaseClient.from('contact_us').insert([insertData])
if (!error) {
message.success(i18n.t('features_contact_form_index_891178'))
}
await submitContactUsForm(insertData)

setIsLoading(false)
return
} catch (err) {
console.log('submit form error:', err)
// console.log('submit form error:', err)
}

setIsLoading(false)
Expand Down
24 changes: 24 additions & 0 deletions services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,27 @@ export const getSupportLinks = async () => {
})
return transformRes(resp)
}

type FormData = {
full_name: string
phone: string
email: string
company: string
job_title: string
region: string
enquiry_type: string
description: string
date: string
time: string
}
const FeishuWebhookUrl = 'https://longbridge.feishu.cn/base/automation/webhook/event/QIbCandqswNUIPhcN3Zck1DWnkg'
export const submitContactUsForm = async (data: FormData) => {
const _data = {
record: data,
}
const resp = await fetch(FeishuWebhookUrl, {
method: 'POST',
body: JSON.stringify(_data),
})
return transformRes(resp)
}

0 comments on commit 8eac064

Please sign in to comment.