Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions app/(dashboard)/assets/imagecase.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions app/(dashboard)/assets/photocase.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
310 changes: 310 additions & 0 deletions app/(dashboard)/settings/_components/AddStaff.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,310 @@
import {
Sheet,
SheetClose,
SheetContent,
SheetTitle,
SheetTrigger,
} from '@/components/ui/sheet';
import { CirclePlus } from 'lucide-react';
import PhotoCase from '@/app/(dashboard)/assets/photocase.svg';
import { ChangeEvent, useState } from 'react';
import { FieldValues, useForm } from 'react-hook-form';
import Image from 'next/image';
import Checkbox from '@/components/Checkbox/Checkbox';
import SuccesModal from '@/components/SuccesModal/SuccesModal';

export function AddStaff() {
const [addImage, setAddImage] = useState(PhotoCase);
const [step, setStep] = useState('form');
const { register, handleSubmit, watch } = useForm();

const handleOnSubmit = (data: FieldValues) => {
data.photo = addImage;
console.log(data);
};

const handleImageUpload = (event: ChangeEvent<HTMLInputElement>) => {
const file = event.target.files?.[0];
if (file) {
setAddImage(URL.createObjectURL(file));
}
};

const handleDeleteImage = () => {
setAddImage(PhotoCase);
};

const nameValue = watch('password');

return (
<Sheet>
<SheetTrigger asChild>
<button
type="button"
onClick={() => setStep('form')}
className="bg-[#091F8E] text-sm text-white rounded-[8px] min-w-28 h-9 px-3 flex items-center justify-center gap-1 font-semibold "
>
<CirclePlus size={16} strokeWidth={3} />
Add Staff
</button>
</SheetTrigger>
{step === 'form' ? (
<SheetContent
// side={'left'}
className="h-[94%] max-h-[900px] sm:max-h-[800px] top-[3%] right-6 overflow-auto sm:max-w-[480px] px-4 pt-4 pb-0"
>
<form onSubmit={handleSubmit(handleOnSubmit)} className="h-full">
<div className="text-sm flex flex-col justify-between gap-5 h-full">
<SheetTitle className="border-b border-[#CBD5E1] pb-2">
Add New Staff
</SheetTitle>

<div className="flex items-center gap-2 px-3">
{addImage && (
<Image
src={addImage}
alt="staff name"
width={64}
height={64}
className="w-16 h-16 rounded-[50%]"
/>
)}
<div>
<input
type="file"
id="photo"
accept="image/*"
onChange={handleImageUpload}
className="hidden"
/>
<label
htmlFor="photo"
className="cursor-pointer text-[#091F8E] font-semibold border-r border-[#94A3B8] pr-2"
>
Upload Photo
</label>
</div>
<div>
<p
onClick={handleDeleteImage}
className="font-semibold text-[#FF063C] cursor-pointer"
>
Delete
</p>
</div>
</div>

<div className="px-3">
<p className="font-semibold mb-2 text-base text-[#334155]">
Staff Information
</p>
<div className="flex flex-col gap-3">
<section className="flex flex-col sm:flex-row items-center justify-between gap-3 text-[#0F172A]">
<div className="flex-[1] w-full">
<label
htmlFor="firstName"
className="font-semibold text-[#475569]"
>
First Name <span className="text-[#FF063C]">*</span>
</label>
<input
{...register('firstName')}
type="text"
placeholder="Enter first name"
className="w-full border border-[#94A3B8] h-9 rounded-[8px] px-[10px] outline-none bg-[#F8F8F8]"
/>
</div>
<div className="flex-[1] w-full">
<label
htmlFor="lastName"
className="font-semibold text-[#475569]"
>
Last Name
</label>
<input
{...register('lastName')}
type="text"
placeholder="Enter last name"
className="w-full border border-[#94A3B8] h-9 rounded-[8px] px-[10px] outline-none bg-[#F8F8F8]"
/>
</div>
</section>
<section className="flex flex-col sm:flex-row items-center justify-between gap-3 text-[#0F172A]">
<div className="flex-[1] w-full">
<label
htmlFor="email"
className="font-semibold text-[#475569]"
>
Email
</label>
<input
{...register('email')}
type="text"
placeholder="user@paystride.com"
className="w-full border border-[#94A3B8] h-9 rounded-[8px] px-[10px] outline-none bg-[#F8F8F8]"
/>
</div>
<div className="flex-[1] w-full">
<label
htmlFor="phoneNumber"
className="font-semibold text-[#475569]"
>
Phone Number
</label>
<input
{...register('phoneNumber')}
type="text"
placeholder="+234"
className="w-full border border-[#94A3B8] h-9 rounded-[8px] px-[10px] outline-none bg-[#F8F8F8]"
/>
</div>
</section>
<section className="flex flex-col sm:flex-row items-center justify-between gap-3 text-[#0F172A]">
<div className="flex-[1] w-full">
<label
htmlFor="department"
className="font-semibold text-[#475569]"
>
Department
</label>
<select
{...register('department')}
id="department"
className="w-full border border-[#94A3B8] h-9 rounded-[8px] px-[10px] outline-none bg-[#F8F8F8]"
>
<option value="" className="text-[#94A3B8]">
Select department
</option>
<option value="sales">Sales</option>
<option value="customerService">
Customer Service
</option>
<option value="inventory">Inventory</option>
<option value="receiving">Receiving</option>
<option value="management">Management</option>
<option value="marketing&merchandising">
Marketing & Merchandising
</option>
<option value="maintenance">Maintenance</option>
<option value="specialityDepartments">
Speciality Departments
</option>
</select>
</div>
<div className="flex-[1] w-full">
<label
htmlFor="role"
className="font-semibold text-[#475569]"
>
Role
</label>
<select
{...register('role')}
id="role"
className="w-full border border-[#94A3B8] h-9 rounded-[8px] px-[10px] outline-none bg-[#F8F8F8]"
>
<option value="" className="text-[#94A3B8]">
Select role
</option>
<option value="cashier">Cashier</option>
<option value="salesAssociate">Sales Associate</option>
<option value="salesManager">Sales Manager</option>
<option value="operationManager">
Operation Manager
</option>
</select>
</div>
</section>
</div>
</div>

<div className="px-3">
<p className="font-semibold mb-2 text-base text-[#334155]">
Security
</p>
<section className="flex flex-col sm:flex-row items-center justify-between gap-3 text-[#0F172A]">
<div className="flex-[1] w-full">
<label
htmlFor="staffNumber"
className="font-semibold text-[#475569]"
>
Staff Number
</label>
<input
{...register('staffNumber')}
type="text"
placeholder="Enter staff number"
className="w-full border border-[#94A3B8] h-9 rounded-[8px] px-[10px] outline-none bg-[#F8F8F8]"
/>
</div>
<div className="flex-[1] w-full">
<label
htmlFor="text"
className="font-semibold text-[#475569]"
>
Password <span className="text-[#FF063C]">*</span>
</label>
<input
{...register('password')}
type="password"
placeholder="Enter password"
className="w-full border border-[#94A3B8] h-9 rounded-[8px] px-[10px] outline-none bg-[#F8F8F8]"
/>
</div>
</section>
</div>

<div className="text-[#0F172A] px-4">
<p className="font-semibold mb-2 text-base text-[#334155]">
Access
</p>
<section className="flex flex-wrap gap-y-2 gap-x-3 text-[#0F172A]">
<div className="flex-[1] w-full">
<Checkbox label="dashboard" register={register} />
</div>
<div className="flex-[1] w-full">
<Checkbox label="transaction" register={register} />
</div>
<div className="flex-[1] w-full">
<Checkbox label="paymentPoint" register={register} />
</div>
<div className="flex-[1] w-full">
<Checkbox label="settlements" register={register} />
</div>
<div className="flex-[2] w-full">
<Checkbox label="settings" register={register} />
</div>
</section>
</div>

<div className="flex justify-between items-center text-[13px] min-[420px]:text-sm font-semibold gap-5 text-center px-3 pb-4">
<SheetClose className="rounded-[8px] py-[10px] px-4 h-10 text-[#091F8E] bg-white border border-[#091F8E]">
Cancel
</SheetClose>

<button
type="submit"
onClick={() => {
setStep('submit');
}}
disabled={!nameValue}
className={`text-[13px] min-[420px]:text-sm rounded-[8px] py-[10px] px-4 h-10 font-semibold ${!nameValue ? 'bg-[#F1F5F9] text-[#94A3B8] pointer-events-none' : 'bg-[#091F8E] text-white'}`}
>
Save Changes
</button>
</div>
</div>
</form>
</SheetContent>
) : (
<SheetContent side={'center'} className="p-2">
<SuccesModal
message="Staff member added successfully!"
close="Return to management"
closeContent="sheet"
/>
</SheetContent>
)}
</Sheet>
);
}
Loading