-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Added upcoming event component. #42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
338148e
3204537
18dbcc7
07415cb
d86c6fa
361bac7
fb7373a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| import "../style/common.css"; | ||
| import "../style/event.css"; | ||
| import { ImageBlock } from "./ImageBlock/ImageBlock"; | ||
| import { Clock, MapPin, ArrowRight } from "lucide-react"; | ||
| import { useNavigate } from "react-router-dom"; | ||
|
|
||
| // Placeholder Constants | ||
| export const DEFAULT_EVENT_IMAGE = "src/images/event-image.png"; | ||
| export const DEFAULT_EVENT_LABEL = "UPCOMING EVENT"; | ||
| export const DEFAULT_USER_ACTION = "SIGN UP"; | ||
| export const DEFAULT_ADMIN_ACTION = "EDIT EVENT"; | ||
|
|
||
| interface EventProps { | ||
| id: string; // Added id for routing to extended page | ||
| imageUrl: string; | ||
| title: string; | ||
| time: Date; | ||
| location: string; | ||
| description: string; | ||
| memberPrice?: string; | ||
| nonMemberPrice?: string; | ||
| role?: "admin" | "user"; | ||
| status: "open" | "waitlist" | "ended"; | ||
| } | ||
|
|
||
| const EventCard: React.FC<EventProps> = ({ | ||
| id, | ||
| imageUrl, | ||
| title, | ||
| time, | ||
| location, | ||
| description, | ||
| memberPrice, | ||
| nonMemberPrice, | ||
| role = "user", | ||
| status, | ||
| }) => { | ||
| const navigate = useNavigate(); | ||
|
|
||
| // Format date: e.g. "2nd April - 6PM" | ||
| const formatDate = (date: Date) => { | ||
| const day = date.getDate(); | ||
| const month = date.toLocaleString("default", { month: "long" }); | ||
| const hours = date.getHours(); | ||
| const ampm = hours >= 12 ? "PM" : "AM"; | ||
| const hour12 = hours % 12 || 12; | ||
|
|
||
| const getOrdinal = (n: number) => { | ||
| const s = ["th", "st", "nd", "rd"]; | ||
| const v = n % 100; | ||
| return n + (s[(v - 20) % 10] || s[v] || s[0]); | ||
| }; | ||
|
|
||
| return `${getOrdinal(day)} ${month} - ${hour12}${ampm}`; | ||
| }; | ||
|
|
||
| const handleActionClick = () => { | ||
| // Eventually navigate to the extended page | ||
| // For now, we'll just log the intent | ||
| console.log(`Navigating to extended page for event: ${id} as ${role}`); | ||
| navigate(`/Events/${id}`); | ||
| }; | ||
|
|
||
| return ( | ||
| <div className="event-card"> | ||
| <div className="event-content"> | ||
| <div className="event-info"> | ||
| <div | ||
| style={{ | ||
| display: "flex", | ||
| justifyContent: "space-between", | ||
| alignItems: "center", | ||
| }} | ||
| > | ||
| <span className="event-label">{DEFAULT_EVENT_LABEL}</span> | ||
| <span className={`event-status status-${status}`}> | ||
| {status.toUpperCase()} | ||
| </span> | ||
| </div> | ||
| <h2 className="event-title">{title}</h2> | ||
|
|
||
| <div className="event-meta"> | ||
| <div className="meta-item"> | ||
| <Clock size={16} className="meta-icon" /> | ||
| <span>{formatDate(time)}</span> | ||
| </div> | ||
| <div className="meta-item"> | ||
| <MapPin size={16} className="meta-icon" /> | ||
| <span>{location}</span> | ||
| </div> | ||
| </div> | ||
|
|
||
| <div className="event-tags"> | ||
| {memberPrice && ( | ||
| <span className="event-tag">{memberPrice} Members</span> | ||
| )} | ||
| {nonMemberPrice && ( | ||
| <span className="event-tag">{nonMemberPrice} Non-Members</span> | ||
| )} | ||
| </div> | ||
|
|
||
| <hr className="event-divider" /> | ||
|
|
||
| <div | ||
| className="event-description" | ||
| dangerouslySetInnerHTML={{ __html: description }} // Need to make sure data is sanitised. | ||
| /> | ||
|
|
||
| <button className="rsvp-button" onClick={handleActionClick}> | ||
| {role === "admin" ? DEFAULT_ADMIN_ACTION : DEFAULT_USER_ACTION} | ||
| <ArrowRight size={18} /> | ||
| </button> | ||
| </div> | ||
| </div> | ||
| <div className="event-image-container"> | ||
| <ImageBlock | ||
| pageKey={imageUrl || DEFAULT_EVENT_IMAGE} | ||
| role="user" | ||
| alt={title} | ||
| style={{ | ||
| width: "100%", | ||
| height: "100%", | ||
| borderRadius: "20px", | ||
| overflow: "hidden", | ||
| }} | ||
| /> | ||
| </div> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export default EventCard; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| import React from "react"; | ||
| import type { UseFormRegisterReturn } from "react-hook-form"; | ||
|
|
||
| interface CurrencyInputProps { | ||
| register: UseFormRegisterReturn; | ||
| placeholder?: string; | ||
| } | ||
|
|
||
| const CurrencyInput: React.FC<CurrencyInputProps> = ({ | ||
| register, | ||
| placeholder, | ||
| }) => { | ||
| const handlePriceKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this all necessary? Wouldn't it be simpler to just use a number field input and then to just round to 2dp? There's also a bug where deleting the period or adding a number after the period results in a temporarily invalid value (shows as invalid until another form input). Furthermore, leaving a period does not show an error until the next form input (at which point an error is raised). |
||
| const isNumber = /\d/.test(e.key); | ||
| const isDot = e.key === "."; | ||
| const isNavigation = [ | ||
| "Backspace", | ||
| "Delete", | ||
| "ArrowLeft", | ||
| "ArrowRight", | ||
| "Tab", | ||
| "Enter", | ||
| ].includes(e.key); | ||
|
|
||
| if (isNavigation || e.ctrlKey || e.metaKey) return; | ||
|
|
||
| const currentVal = e.currentTarget.value; | ||
| const selectionStart = e.currentTarget.selectionStart ?? 0; | ||
|
|
||
| if (isDot && currentVal.includes(".")) { | ||
| e.preventDefault(); | ||
| return; | ||
| } | ||
|
|
||
| if (currentVal.includes(".") && isNumber) { | ||
| const dotIndex = currentVal.indexOf("."); | ||
| const decimals = currentVal.split(".")[1]; | ||
| if (decimals && decimals.length >= 2 && selectionStart > dotIndex) { | ||
| e.preventDefault(); | ||
| return; | ||
| } | ||
| } | ||
|
|
||
| if (!isNumber && !isDot) { | ||
| e.preventDefault(); | ||
| } | ||
| }; | ||
|
|
||
| return ( | ||
| <div className="currency-input-wrapper"> | ||
| <span className="currency-prefix">$</span> | ||
| <input | ||
| type="text" | ||
| placeholder={placeholder} | ||
| onKeyDown={handlePriceKeyDown} | ||
| {...register} | ||
| /> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export default CurrencyInput; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| import React from "react"; | ||
|
|
||
| interface FormFieldProps { | ||
| label: string; | ||
| error?: string; | ||
| children: React.ReactNode; | ||
| className?: string; | ||
| } | ||
|
|
||
| const FormField: React.FC<FormFieldProps> = ({ | ||
| label, | ||
| error, | ||
| children, | ||
| className = "", | ||
| }) => { | ||
| return ( | ||
| <div className={`form-group ${className}`}> | ||
| <label>{label}</label> | ||
| {children} | ||
| {error && <span className="error-text">{error}</span>} | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export default FormField; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| import { useEditor, EditorContent } from "@tiptap/react"; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| import StarterKit from "@tiptap/starter-kit"; | ||
| import Underline from "@tiptap/extension-underline"; | ||
| import { useEffect, useState } from "react"; | ||
| import { | ||
| Bold, | ||
| Italic, | ||
| Underline as UnderlineIcon, | ||
| List, | ||
| ListOrdered, | ||
| Undo, | ||
| Redo, | ||
| } from "lucide-react"; | ||
|
|
||
| interface RichTextEditorProps { | ||
| value: string; | ||
| onChange: (value: string) => void; | ||
| } | ||
|
|
||
| const RichTextEditor = ({ value, onChange }: RichTextEditorProps) => { | ||
| const [, setUpdateCount] = useState(0); | ||
|
|
||
| const editor = useEditor({ | ||
| extensions: [StarterKit, Underline], | ||
| content: value, | ||
| onUpdate: ({ editor }) => { | ||
| onChange(editor.getHTML()); | ||
| }, | ||
| onTransaction: () => { | ||
| setUpdateCount((prev) => prev + 1); | ||
| }, | ||
| }); | ||
|
|
||
| useEffect(() => { | ||
| if (editor && value !== editor.getHTML()) { | ||
| editor.commands.setContent(value); | ||
| } | ||
| }, [value, editor]); | ||
|
|
||
| if (!editor) { | ||
| return null; | ||
| } | ||
|
|
||
| return ( | ||
| <div className="tiptap-editor-container"> | ||
| <div className="editor-toolbar"> | ||
| <button | ||
| type="button" | ||
| onClick={() => editor.chain().focus().toggleBold().run()} | ||
| className={editor.isActive("bold") ? "is-active" : ""} | ||
| title="Bold (Ctrl+B)" | ||
| > | ||
| <Bold size={18} /> | ||
| </button> | ||
| <button | ||
| type="button" | ||
| onClick={() => editor.chain().focus().toggleItalic().run()} | ||
| className={editor.isActive("italic") ? "is-active" : ""} | ||
| title="Italic (Ctrl+I)" | ||
| > | ||
| <Italic size={18} /> | ||
| </button> | ||
| <button | ||
| type="button" | ||
| onClick={() => editor.chain().focus().toggleUnderline().run()} | ||
| className={editor.isActive("underline") ? "is-active" : ""} | ||
| title="Underline (Ctrl+U)" | ||
| > | ||
| <UnderlineIcon size={18} /> | ||
| </button> | ||
|
|
||
| <div className="divider" /> | ||
|
|
||
| <button | ||
| type="button" | ||
| onClick={() => editor.chain().focus().toggleBulletList().run()} | ||
| className={editor.isActive("bulletList") ? "is-active" : ""} | ||
| title="Bullet List" | ||
| > | ||
| <List size={18} /> | ||
| </button> | ||
| <button | ||
| type="button" | ||
| onClick={() => editor.chain().focus().toggleOrderedList().run()} | ||
| className={editor.isActive("orderedList") ? "is-active" : ""} | ||
| title="Numbered List" | ||
| > | ||
| <ListOrdered size={18} /> | ||
| </button> | ||
|
|
||
| <div className="divider" /> | ||
|
|
||
| <button | ||
| type="button" | ||
| onClick={() => editor.chain().focus().undo().run()} | ||
| disabled={!editor.can().undo()} | ||
| title="Undo" | ||
| > | ||
| <Undo size={18} /> | ||
| </button> | ||
| <button | ||
| type="button" | ||
| onClick={() => editor.chain().focus().redo().run()} | ||
| disabled={!editor.can().redo()} | ||
| title="Redo" | ||
| > | ||
| <Redo size={18} /> | ||
| </button> | ||
| </div> | ||
| <EditorContent editor={editor} className="tiptap-content" /> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export default RichTextEditor; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,7 @@ import Contact from "../pages/Contact.tsx"; | |
| import Sponsors from "../pages/Sponsors.tsx"; | ||
| import Events from "../pages/Events.tsx"; | ||
| import About from "../pages/About.tsx"; | ||
| import AdminEventEditor from "../pages/AdminEventEditor.tsx"; | ||
| import SignUp from "../pages/Signup.tsx"; | ||
|
|
||
| const App = () => { | ||
|
|
@@ -29,6 +30,7 @@ const App = () => { | |
| <Route path="" element={<Home />} /> | ||
| <Route path="About" element={<About />} /> | ||
| <Route path="Events" element={<Events />} /> | ||
| <Route path="Events/:eventId" element={<AdminEventEditor />} /> | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should link to a general event page instead, do the default user side of things, and then introduce admin editing capavilities afterwards. Admin functionality is something we consider as an extension of default user functionality. Where sensible, it would be good to build admin functionality from the default user view. This is mainly to make the admin a user with elevated permissions rather than someone who accesses the site differently. I think a good result of this is that everything visible to a user is made visible to an admin without needing extra effort (e.g. custom user view, or logging in with a different account). |
||
| <Route path="Sponsors" element={<Sponsors />} /> | ||
| <Route path="Contact" element={<Contact />} /> | ||
| <Route path="Faq" element={<Faq />} /> | ||
|
|
||

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As an extension of my comment in
AdminEventEditor.tsxThis should link to a general event page instead.