Skip to content

Commit

Permalink
add logo upload
Browse files Browse the repository at this point in the history
  • Loading branch information
DeepanshuMishraa committed Oct 23, 2024
1 parent b67c0ee commit dd9be4b
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 150 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "Company" ADD COLUMN "logo" TEXT;
1 change: 1 addition & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ model User {
model Company {
id String @id @default(cuid())
name String
logo String?
website String?
description String?
jobs Job[]
Expand Down
3 changes: 2 additions & 1 deletion src/actions/auth.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export const signUp = withServerActionAsyncCatcher<
name: _data.companyInfo.name,
website: _data.companyInfo.website || '',
description: _data.companyInfo.description || '',
logo: _data.companyInfo.logo || '',
userId: user.id,
},
});
Expand All @@ -84,14 +85,14 @@ export const signUp = withServerActionAsyncCatcher<
title: 'Company Profile',
companyName: _data.companyInfo.name,
companyBio: _data.companyInfo.description || '',
companyLogo: _data.companyInfo.logo || '',
companyEmail: baseData.email,
category: 'Company',
type: 'Full_time',
workMode: 'office',
city: '',
address: '',
application: '',
companyLogo: '',
skills: [],
},
});
Expand Down
149 changes: 0 additions & 149 deletions src/components/Onboarding.tsx

This file was deleted.

35 changes: 35 additions & 0 deletions src/components/auth/signup.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use client';
import { useState } from 'react';
import { useRouter } from 'next/navigation';
import Image from 'next/image';

import { Button } from '@/components/ui/button';
import { Input } from '@/components/ui/input';
Expand Down Expand Up @@ -31,6 +32,7 @@ export const Signup = () => {
const { toast } = useToast();
const router = useRouter();
const [isHr, setIsHr] = useState(false);
const [logoPreview, setLogoPreview] = useState<string | null>(null);

const form = useForm<SignupData>({
resolver: zodResolver(SignupSchema),
Expand All @@ -51,6 +53,17 @@ export const Signup = () => {
},
});

const handleLogoChange = (event: React.ChangeEvent<HTMLInputElement>) => {
const file = event.target.files?.[0];
if (file) {
const reader = new FileReader();
reader.onloadend = () => {
setLogoPreview(reader.result as string);
};
reader.readAsDataURL(file);
}
};

async function signupHandler(data: Omit<SignupData, 'companyInfo'>) {
try {
const signupData: SignupData = {
Expand Down Expand Up @@ -190,6 +203,28 @@ export const Signup = () => {
</FormItem>
)}
/>
<FormItem>
<FormLabel>Company Logo</FormLabel>
<FormControl>
<Input
type="file"
accept="image/*"
onChange={handleLogoChange}
/>
</FormControl>
{logoPreview && (
<div className="mt-2">
<Image
src={logoPreview}
alt="Company Logo Preview"
width={100}
height={100}
className="object-contain"
/>
</div>
)}
<FormMessage />
</FormItem>
</div>
)}

Expand Down
2 changes: 2 additions & 0 deletions src/lib/validators/auth.validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ export const companySetupSchema = z.object({
companyName: z.string().min(1, 'Company name is required'),
companyWebsite: z.string().url('Invalid URL'),
description: z.string().min(10, 'Description must be at least 10 characters'),
logo: z.string().optional(),
});

// Define the company info schema
export const CompanyInfoSchema = z.object({
name: z.string(),
website: z.string().optional(),
description: z.string().optional(),
logo: z.string().optional(),
});

// Extend the base signup schema
Expand Down

0 comments on commit dd9be4b

Please sign in to comment.