Skip to content

Commit

Permalink
Merge branch 'main' into issue-197-Connect_Volunteer_Multi-Select_fro…
Browse files Browse the repository at this point in the history
…ntend_to_backend
  • Loading branch information
dct0 authored Apr 29, 2024
2 parents 1fdf82c + a93cc48 commit 5238694
Show file tree
Hide file tree
Showing 29 changed files with 522 additions and 208 deletions.
38 changes: 38 additions & 0 deletions prisma/migrations/20240210012417_issue_200/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
Warnings:
- The primary key for the `RepairRequest` table will be changed. If it partially fails, the table could be left without primary key constraint.
- The `id` column on the `RepairRequest` table would be dropped and recreated. This will lead to data loss if there is data in the column.
- You are about to drop the column `organisationId` on the `Staff` table. All the data in the column will be lost.
- You are about to drop the `Brand` table. If the table is not empty, all the data it contains will be lost.
- You are about to drop the `Organisation` table. If the table is not empty, all the data it contains will be lost.
- Changed the type of `repairRequestId` on the `RepairRequestImage` table. No cast exists, the column would be dropped and recreated, which cannot be done if there is data, since the column is required.
*/
-- DropForeignKey
ALTER TABLE "RepairRequestImage" DROP CONSTRAINT "RepairRequestImage_repairRequestId_fkey";

-- DropForeignKey
ALTER TABLE "Staff" DROP CONSTRAINT "Staff_organisationId_fkey";

-- AlterTable
ALTER TABLE "RepairRequest" DROP CONSTRAINT "RepairRequest_pkey",
DROP COLUMN "id",
ADD COLUMN "id" SERIAL NOT NULL,
ADD CONSTRAINT "RepairRequest_pkey" PRIMARY KEY ("id");

-- AlterTable
ALTER TABLE "RepairRequestImage" DROP COLUMN "repairRequestId",
ADD COLUMN "repairRequestId" INTEGER NOT NULL;

-- AlterTable
ALTER TABLE "Staff" DROP COLUMN "organisationId";

-- DropTable
DROP TABLE "Brand";

-- DropTable
DROP TABLE "Organisation";

-- AddForeignKey
ALTER TABLE "RepairRequestImage" ADD CONSTRAINT "RepairRequestImage_repairRequestId_fkey" FOREIGN KEY ("repairRequestId") REFERENCES "RepairRequest"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
24 changes: 6 additions & 18 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ enum UserRole {
}

model RepairRequest {
id String @id @default(uuid())
id Int @id @default(autoincrement())
createdBy String //User id
assignedTo String @default("") //volunteer id
assignedTo String @default("") //volugit adnteer id
event Event @relation(fields: [eventId], references: [id]) //relation field (many repair_requests to one event)
eventId String
Expand Down Expand Up @@ -89,16 +89,12 @@ model ItemType {
events Event[]
}

model Brand {
name String @id
}

model RepairRequestImage {
id String @id @default(uuid())
s3Key String //Potentially to be changed for privacy reasons
repairRequest RepairRequest @relation(fields: [repairRequestId], references: [id])
repairRequestId String
repairRequestId Int
}

model EventImage {
Expand All @@ -118,16 +114,8 @@ model EventRepairer {
@@unique([userId, eventId])
}

model Organisation {
id String @id @default(uuid())
name String @unique
Roles Staff[]
}

model Staff {
id String @id @default(uuid())
clerkId String
role UserRole
org Organisation @relation(fields: [organisationId], references: [id])
organisationId String
id String @id @default(uuid())
clerkId String
role UserRole
}
15 changes: 6 additions & 9 deletions prisma/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
/* eslint-disable no-console */
import { faker } from "@faker-js/faker";
import {
Brand,
Event,
EventRepairer,
ItemType,
Expand Down Expand Up @@ -46,14 +45,12 @@ async function createItemTypes(itemTypeNames: string[]) {
}

async function createBrands(brandNames: string[]) {
const brands: Brand[] = [];
const brands: string[] = [];

for (const name of brandNames) {
const brand = await prisma.brand.create({
data: { name }
});
const brand = name;

brands.push(brand);
brands.push(name);
console.log(brand);
}

Expand Down Expand Up @@ -97,7 +94,7 @@ async function createRandomRepairRequests(
count: number,
events: Event[],
itemTypes: ItemType[],
brands: Brand[]
brands: string[]
) {
const repairRequests: RepairRequest[] = [];

Expand All @@ -112,7 +109,7 @@ async function createRandomRepairRequests(
status: "PENDING",
description: faker.lorem.sentence(),
comment: faker.lorem.sentence(),
itemBrand: faker.helpers.arrayElement(brands).name,
itemBrand: faker.helpers.arrayElement(brands),
itemMaterial: faker.word.noun(),
requestDate: faker.date.past(),
updatedAt: faker.date.recent(),
Expand Down Expand Up @@ -169,7 +166,7 @@ async function main() {
faker.seed(fakerSeed);
await deleteAllData();
const itemTypes: ItemType[] = await createItemTypes(itemTypeNames);
const brands: Brand[] = await createBrands(brandNames);
const brands: string[] = await createBrands(brandNames);
const events: Event[] = await createRandomEvents(eventCount, itemTypes);
// const repairRequests: RepairRequest[] =
await createRandomRepairRequests(
Expand Down
131 changes: 131 additions & 0 deletions src/components/DropDown/skill-dropdown.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
import React, { useState, Fragment, useRef, useEffect } from "react";

Check warning on line 1 in src/components/DropDown/skill-dropdown.tsx

View workflow job for this annotation

GitHub Actions / Run ESLint

Run autofix to sort these imports!
import { Menu, Transition } from "@headlessui/react";
import SelectedOption from "@/components/Tag/tag";
import { GoChevronUp, GoChevronDown } from "react-icons/go";

// Define skills
const options = [
"toys",
"bikes",
"furniture",
"clothing",
"jewellery",
"curtains",
"household items",
"garden tools"
];

const Dropdown: React.FC = () => {
const [selectedItems, setSelectedItems] = useState<string[]>([]);
const [isOpen, setIsOpen] = useState(false);
const [filter, setFilter] = useState("");
const wrapperRef = useRef<HTMLDivElement>(null);
const filteredOptions = options.filter((option) =>
option.toLowerCase().includes(filter.toLowerCase())
);

const toggleItem = (item: string) => {
if (selectedItems.includes(item)) {
setSelectedItems(selectedItems.filter((i) => i !== item));
} else {
setSelectedItems([...selectedItems, item]);
}
setFilter("");
};

const removeItem = (item: string) => {
setSelectedItems(selectedItems.filter((i) => i !== item));
};

useEffect(() => {
const handleClickOutside = (event: MouseEvent) => {
if (
wrapperRef.current &&
!wrapperRef.current.contains(event.target as Node)
) {
setIsOpen(false);
}
};
if (isOpen) {
document.addEventListener("mousedown", handleClickOutside);
} else {
document.removeEventListener("mousedown", handleClickOutside);
}
return () => {
document.removeEventListener("mousedown", handleClickOutside);
};
}, [isOpen]);

return (
<div ref={wrapperRef}>
<Menu as="div" className="relative inline-block text-left w-full">
<div className="flex border-2 border-slate-300 rounded-md">
<div className="flex flex-wrap items-center flex-grow">
{selectedItems.map((item) => (
<SelectedOption key={item} option={item} onRemove={removeItem} />
))}
{(!selectedItems.length || isOpen) && (
<input
type="text"
className="flex-1 pl-1 m-1 text-sm w-full focus:outline-none"
value={filter}
onChange={(e) => setFilter(e.target.value)}
onFocus={() => setIsOpen(true)}
placeholder="Add Skills"
/>
)}
</div>
<Menu.Button
className="px-4 py-2 bg-slate-50 text-primary-600 rounded-r-md"
onClick={() => setIsOpen((prevIsOpen) => !prevIsOpen)}
>
{isOpen ? <GoChevronUp /> : <GoChevronDown />}
</Menu.Button>
</div>
{isOpen && (
<Transition
show={isOpen}
as={Fragment}
enter="transition ease-out duration-100"
enterFrom="transform opacity-0 scale-95"
enterTo="transform opacity-100 scale-100"
leave="transition ease-in duration-75"
leaveFrom="transform opacity-100 scale-100"
leaveTo="transform opacity-0 scale-95"
>
<Menu.Items
static
className="absolute w-full mt-2 origin-top-right bg-white divide-y border-slate-300 rounded-md shadow-lg ring-1 ring-grey-950 ring-opacity-5 focus:outline-none z-50 max-h-60 overflow-auto"
>
<div className="px-1 py-1">
{filteredOptions.map((option) => (
<Menu.Item key={option}>
{({ active }) => (
<button
onClick={() => toggleItem(option)}
className={`${
active
? "bg-lightAqua-500 text-white"
: "text-gray-900"
} group flex rounded-md items-center w-full px-2 py-2 text-sm`}
>
{option}
</button>
)}
</Menu.Item>
))}
{filteredOptions.length === 0 && (
<div className="px-4 py-2 text-sm text-gray-500">
No skills found
</div>
)}
</div>
</Menu.Items>
</Transition>
)}
</Menu>
</div>
);
};

export default Dropdown;
2 changes: 1 addition & 1 deletion src/components/EventBox/request-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { User } from "@/types";

// Contains type of info stored in our event box.
type RequestProps = {
repairRequestId: string;
repairRequestId: number;
createdBy: User;
requestDate: string;
itemType: string;
Expand Down
Loading

0 comments on commit 5238694

Please sign in to comment.