From e689ff8f6bb24418a129a75b6ffb11dfa44b8a8b Mon Sep 17 00:00:00 2001 From: Ashutoshpadhi629 Date: Tue, 24 Sep 2024 02:48:42 +0530 Subject: [PATCH] minor/ui-bugs --- src/components/job-form.tsx | 14 +++++--------- src/layouts/header.tsx | 2 +- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/components/job-form.tsx b/src/components/job-form.tsx index e2d97c28..bb167f51 100644 --- a/src/components/job-form.tsx +++ b/src/components/job-form.tsx @@ -32,6 +32,7 @@ import { FaFileUpload } from 'react-icons/fa'; import { Switch } from './ui/switch'; import { Label } from './ui/label'; import dynamic from 'next/dynamic'; +import { uploadFileAction } from '@/actions/upload-to-cdn'; const DynamicLineDrawingAnimation = dynamic( () => import('./gmaps-autosuggest'), @@ -87,16 +88,12 @@ const PostJobForm = () => { const uniqueFileName = `${Date.now()}-${file.name}`; formData.append('uniqueFileName', uniqueFileName); - const res = await fetch(`/api/upload-to-cdn`, { - method: 'POST', - body: formData, - }); - - if (!res.ok) { + const res = await uploadFileAction(formData); + if (!res) { throw new Error('Failed to upload image'); } - const uploadRes = await res.json(); + const uploadRes = res; return uploadRes.url; } catch (error) { console.error('Image upload failed:', error); @@ -126,8 +123,7 @@ const PostJobForm = () => { const response = await createJob(data); if (!response.status) { return toast({ - title: response.name || 'Something went wrong', - description: response.message || 'Internal server error', + title: response.message || 'Error', variant: 'destructive', }); } diff --git a/src/layouts/header.tsx b/src/layouts/header.tsx index e5c90389..0121fc55 100644 --- a/src/layouts/header.tsx +++ b/src/layouts/header.tsx @@ -46,7 +46,7 @@ const Header = () => { return ( <> -