The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Midway implementing allowing attachments in support form 2
Joshen Limc77697a8b1c2
diff --git a/studio/components/interfaces/Support/SupportForm.tsx b/studio/components/interfaces/Support/SupportForm.tsxindex 50cb103576a..ac115f5df5d 100644--- a/studio/components/interfaces/Support/SupportForm.tsx+++ b/studio/components/interfaces/Support/SupportForm.tsx@@ -11,7 +11,7 @@ import { API_URL, PRICING_TIER_PRODUCT_IDS } from 'lib/constants'import Divider from 'components/ui/Divider'import Connecting from 'components/ui/Loading/Loading'-import { formReducer } from './SupportForm.utils'+import { formReducer, uploadAttachments } from './SupportForm.utils'import {DEFAULT_VALUES,CATEGORY_OPTIONS,@@ -32,7 +32,7 @@ const SupportForm: FC<Props> = ({ setSent }) => {const [loading, setLoading] = useState<boolean>(false)const [formState, formDispatch] = useReducer(formReducer, DEFAULT_VALUES)- const [uploadedFiles, setUploadedFiles] = useState<any>()+ const [uploadedFiles, setUploadedFiles] = useState<File[]>()const [uploadedDataUrls, setUploadedDataUrls] = useState<any>([])// Get all orgs and projects from global store@@ -73,11 +73,12 @@ const SupportForm: FC<Props> = ({ setSent }) => {useEffect(() => {if (!uploadedFiles) return-- console.log('UploadedFiles changed', uploadedFiles)const objectUrls = Array.prototype.map.call(uploadedFiles, (file) => URL.createObjectURL(file))- console.log('objectUrls', objectUrls)setUploadedDataUrls(objectUrls)++ return () => {+ objectUrls.forEach((url: any) => URL.revokeObjectURL(url))+ }}, [uploadedFiles])function handleOnChange(x: any) {@@ -124,6 +125,12 @@ const SupportForm: FC<Props> = ({ setSent }) => {if (errors.length === 0) {const projectRef = formState.project.value++ if (uploadedFiles) {+ const uploadedAttachments = await uploadAttachments(projectRef, uploadedFiles)+ console.log(uploadedAttachments)+ }+const payload = {projectRef,message: formState.body.value,@@ -145,19 +152,21 @@ const SupportForm: FC<Props> = ({ setSent }) => {}}- setLoading(true)- const response = await post(`${API_URL}/feedback/send`, payload)- setLoading(false)-- if (response.error) {- ui.setNotification({- category: 'error',- message: `Failed to submit support ticket: ${response.error.message}`,- })- } else {- ui.setNotification({ category: 'success', message: 'Support request sent. Thank you!' })- setSent(true)- }+ ui.setNotification({ category: 'success', message: 'hehe' })++ // setLoading(true)+ // const response = await post(`${API_URL}/feedback/send`, payload)+ // setLoading(false)++ // if (response.error) {+ // ui.setNotification({+ // category: 'error',+ // message: `Failed to submit support ticket: ${response.error.message}`,+ // })+ // } else {+ // ui.setNotification({ category: 'success', message: 'Support request sent. Thank you!' })+ // setSent(true)+ // }}}diff --git a/studio/components/interfaces/Support/SupportForm.utils.ts b/studio/components/interfaces/Support/SupportForm.utils.tsindex f54f95bc466..fe4815a0cf5 100644--- a/studio/components/interfaces/Support/SupportForm.utils.ts+++ b/studio/components/interfaces/Support/SupportForm.utils.ts@@ -1,3 +1,8 @@+import { createClient } from '@supabase/supabase-js'+import { IS_PLATFORM } from 'lib/constants'+import { uuidv4 } from 'lib/helpers'+import { post } from 'lib/common/fetch'+export function formReducer(state: any, action: any) {return {...state,@@ -7,3 +12,29 @@ export function formReducer(state: any, action: any) {},}}++export const uploadAttachments = async (ref: string, files: File[]) => {+ const filesToUpload = Array.from(files)+ return Promise.all(+ filesToUpload.map(async (file) => {+ // [Joshen] Left off here - trying to figure out how to+ // pass the files into the next API, which will upload the files then through+ // the Supabase client+ const res = await post('/api/upload-attachments', files, {+ headers: { 'Content-Type': 'multipart/form-data' },+ })++ // const prefix = `${ref}/${uuidv4()}`+ // const options = { cacheControl: '3600' }++ // const { data, error } = await supportSupabaseClient.storage+ // .from('support-attachments')+ // .upload(prefix, file, options)++ // if (error) {+ // console.log('error', error)+ // }+ // return data+ })+ )+}diff --git a/studio/localStores/storageExplorer/StorageExplorerStore.js b/studio/localStores/storageExplorer/StorageExplorerStore.jsindex 43b37125015..e9b3eb9e7dd 100644--- a/studio/localStores/storageExplorer/StorageExplorerStore.js+++ b/studio/localStores/storageExplorer/StorageExplorerStore.js@@ -637,7 +637,7 @@ class StorageExplorerStore {// Upload files in batchesconst promises = formattedFilesToUpload.map((file) => {- const fileOptions = { cacheControl: 3600 }+ const fileOptions = { cacheControl: '3600' }const metadata = { mimetype: file.type, size: file.size }const isWithinFolder = get(file, ['path'], '').split('/').length > 1diff --git a/studio/pages/api/upload-attachments.tsx b/studio/pages/api/upload-attachments.tsxnew file mode 100644index 00000000000..90ca3aa6255--- /dev/null+++ b/studio/pages/api/upload-attachments.tsx@@ -0,0 +1,42 @@+import { NextApiRequest, NextApiResponse } from 'next'+import { createClient } from '@supabase/supabase-js'+import SqlString from 'sqlstring'++import apiWrapper from 'lib/api/apiWrapper'+import { IS_PLATFORM } from 'lib/constants'+import { constructHeaders } from 'lib/api/apiHelpers'+import { post } from 'lib/common/fetch'+import { tryParseInt } from 'lib/helpers'++// [Joshen TODO] To be shifted into an env vars before doing anything+// Both bitwarden, .env, and vercel+const API_URL = 'https://mfrkmguhoejspftfvgdz.supabase.co'+const API_KEY =+ 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoiYW5vbiIsImlhdCI6MTYyNzg4NjQ0MCwiZXhwIjoxOTQzNDYyNDQwfQ.wRGmWXOORz-cxVBof4WLOSxRog9Tdff1P8gI72U8ta8'++export default (req: NextApiRequest, res: NextApiResponse) => apiWrapper(req, res, handler)++async function handler(req: NextApiRequest, res: NextApiResponse) {+ const { method } = req++ switch (method) {+ case 'POST':+ return handlePost(req, res)+ default:+ res.setHeader('Allow', ['POST'])+ res.status(405).json({ data: null, error: { message: `Method ${method} Not Allowed` } })+ }+}++const handlePost = async (req: NextApiRequest, res: NextApiResponse) => {+ if (!IS_PLATFORM) return res.status(200).json({})++ const supportSupabaseClient = createClient(API_URL, API_KEY)+ console.log('Upload attachments', req.body)++ console.log()+ console.log('Files', req.body.files[0])+ console.log()++ return res.status(200).json({ ping: 'pong' })+}