Created
August 15, 2022 23:26
-
-
Save jjhiggz/f82f22854a40dd66b0737600893f6943 to your computer and use it in GitHub Desktop.
Sidebar Stuff
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const DragoverBar = ({ | |
disabled = false, | |
onDragEnter, | |
onDragLeave, | |
isFirst = false, | |
}: { | |
onDragEnter: () => void; | |
onDragLeave: () => void; | |
isFirst?: boolean; | |
disabled?: boolean; | |
}) => { | |
return ( | |
<div | |
className={`drag-to-box dragover ${isFirst ? "first" : ""}`} | |
onDragEnter={(e) => { | |
e.preventDefault(); | |
onDragEnter(); | |
}} | |
onDragLeave={(e) => { | |
e.preventDefault(); | |
onDragLeave(); | |
}} | |
onDrop={(_e) => {}} | |
onDragOver={(e) => { | |
e.preventDefault(); | |
}} | |
> | |
{!disabled && ( | |
<div className="drag-to-line"> | |
<div className="circle"></div> | |
<div className="line"></div> | |
</div> | |
)} | |
</div> | |
); | |
}; | |
export default DragoverBar; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
generator client { | |
provider = "prisma-client-js" | |
previewFeatures = ["interactiveTransactions"] | |
} | |
datasource db { | |
provider = "postgresql" | |
url = env("DATABASE_URL") | |
} | |
model User { | |
id String @id @default(cuid()) | |
email String @unique | |
createdAt DateTime @default(now()) | |
updatedAt DateTime @updatedAt | |
role Role | |
items Item[] | |
menus Menu[] | |
notes Note[] | |
password Password? | |
restaurants Restaurant[] | |
sections Section[] | |
} | |
model Restaurant { | |
id String @id @default(cuid()) | |
name String | |
description String @default("") | |
address String @default("") | |
createdAt DateTime @default(now()) | |
updatedAt DateTime @updatedAt | |
userId String | |
order Int | |
showMenus Boolean @default(false) | |
entityType RestaurantType @default(RESTAURANT) | |
user User @relation(fields: [userId], references: [id], onDelete: Cascade) | |
items Item[] | |
menus Menu[] | |
sections Section[] | |
@@unique([userId, name]) | |
@@unique([userId, order]) | |
} | |
model Menu { | |
id String @id @default(cuid()) | |
name String @default("") | |
description String @default("") | |
timeOfDay String @default("") | |
footer String @default("") | |
createdAt DateTime @default(now()) | |
updatedAt DateTime @updatedAt | |
restaurantId String | |
userId String | |
showSections Boolean @default(false) | |
order Int | |
entityType MenuType @default(MENU) | |
restaurant Restaurant @relation(fields: [restaurantId], references: [id], onDelete: Cascade) | |
user User @relation(fields: [userId], references: [id], onDelete: Cascade) | |
Item Item[] | |
sections Section[] | |
@@unique([restaurantId, order]) | |
} | |
model Section { | |
id String @id @default(cuid()) | |
name String @default("") | |
description String @default("") | |
timeOfDay String @default("") | |
createdAt DateTime @default(now()) | |
updatedAt DateTime @updatedAt | |
menuId String | |
userId String | |
restaurantId String | |
showItems Boolean @default(false) | |
order Int | |
entityType SectionType @default(SECTION) | |
menu Menu @relation(fields: [menuId], references: [id], onDelete: Cascade) | |
Restaurant Restaurant @relation(fields: [restaurantId], references: [id]) | |
user User @relation(fields: [userId], references: [id], onDelete: Cascade) | |
items Item[] | |
@@unique([menuId, order]) | |
} | |
model Item { | |
id String @id @default(cuid()) | |
name String @default("") | |
description String @default("") | |
timeOfDay String @default("") | |
price String @default("0.00") | |
photoUrl String @default("") | |
createdAt DateTime @default(now()) | |
updatedAt DateTime @updatedAt | |
sectionId String | |
userId String | |
restaurantId String | |
menuId String | |
order Int | |
isVegetarian Boolean @default(false) | |
isVegan Boolean @default(false) | |
isKosher Boolean @default(false) | |
isHalal Boolean @default(false) | |
isOrganic Boolean @default(false) | |
isGlutenFree Boolean @default(false) | |
entityType ItemType @default(ITEM) | |
menu Menu @relation(fields: [menuId], references: [id], onDelete: Cascade) | |
restaurant Restaurant @relation(fields: [restaurantId], references: [id]) | |
section Section @relation(fields: [sectionId], references: [id], onDelete: Cascade) | |
user User @relation(fields: [userId], references: [id], onDelete: Cascade) | |
@@unique([sectionId, order]) | |
} | |
enum Role { | |
DEV | |
CLIENT | |
ADMIN | |
} | |
enum RestaurantType { | |
RESTAURANT | |
} | |
enum MenuType { | |
MENU | |
} | |
enum SectionType { | |
SECTION | |
} | |
enum ItemType { | |
ITEM | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// in routes/api/toggle-children.ts | |
import { Response } from "@remix-run/node"; | |
import type { ActionFunction } from "@remix-run/server-runtime"; | |
import { prisma } from "~/db.server"; | |
import { requireUserId } from "~/session.server"; | |
export type ToggleChildren = { | |
type: "restaurant" | "menu" | "section"; | |
id: string; | |
currentStatus: boolean; | |
}; | |
export const action: ActionFunction = async ({ request }) => { | |
// eslint-disable-next-line @typescript-eslint/no-unused-vars | |
const userId = await requireUserId(request); | |
const formData: ToggleChildren = await request | |
.formData() | |
.then((formData) => formData.get("JSON") as string) | |
.then((jsonData) => JSON.parse(jsonData)); | |
const { currentStatus, id, type } = formData; | |
if (type === "restaurant") { | |
await prisma.restaurant.update({ | |
where: { | |
id, | |
}, | |
data: { | |
showMenus: !currentStatus, | |
}, | |
}); | |
} | |
if (type === "menu") { | |
await prisma.menu.update({ | |
where: { | |
id, | |
}, | |
data: { | |
showSections: !currentStatus, | |
}, | |
}); | |
} | |
if (type === "section") { | |
await prisma.section.update({ | |
where: { | |
id, | |
}, | |
data: { | |
showItems: !currentStatus, | |
}, | |
}); | |
} | |
return new Response(JSON.stringify("reordered"), { | |
status: 200, | |
headers: { | |
"Content-Type": "application/json", | |
}, | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment