Skip to content
This repository has been archived by the owner on Aug 7, 2024. It is now read-only.

[BUG] Duplicate select form element #8147 #8220

Merged
merged 32 commits into from
Aug 6, 2023
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
de9a463
removed duplicate dropdown and created single select component
mianakbarjan Jul 16, 2023
9294360
fixed typos in manage event and manage milestone
mianakbarjan Jul 16, 2023
34450d9
improved naming convention
mianakbarjan Jul 16, 2023
f6efd5d
Merge branch 'main' into main
mianakbarjan Jul 17, 2023
7fbc005
Requested changes made
mianakbarjan Jul 17, 2023
f3a681c
Merge branch 'main' of https://github.com/mianakbarjan/LinkFree
mianakbarjan Jul 17, 2023
2998668
Merge branch 'main' into main
mianakbarjan Jul 19, 2023
6b2fde5
errors fixed
mianakbarjan Jul 19, 2023
25f3da9
Merge branch 'main' into main
mianakbarjan Jul 24, 2023
1fc2b05
requested changes made and errors fixed
mianakbarjan Jul 24, 2023
6e282cb
Merge branch 'main' into main
mianakbarjan Jul 24, 2023
ad95c02
id same as name
mianakbarjan Jul 24, 2023
5a1de7d
Merge branch 'main' of https://github.com/mianakbarjan/LinkFree
mianakbarjan Jul 24, 2023
919de85
Merge branch 'main' into main
mianakbarjan Jul 25, 2023
9c73631
Label attribute added to all components
mianakbarjan Jul 25, 2023
6e081ff
changed file names to remove conflict
mianakbarjan Jul 31, 2023
4f74ae1
edits
mianakbarjan Jul 31, 2023
66865d8
Rename navigation.js to Navigation.js
mianakbarjan Jul 31, 2023
0ef5efa
Merge branch 'main' into main
mianakbarjan Jul 31, 2023
a0d35b0
updated code
mianakbarjan Jul 31, 2023
4246e65
Merge branch 'main' into main
mianakbarjan Aug 1, 2023
2de61b6
Merge branch 'main' into main
mianakbarjan Aug 5, 2023
2a493a4
fixed events test error
mianakbarjan Aug 5, 2023
b0dff6a
Merge branch 'main' of https://github.com/mianakbarjan/LinkFree
mianakbarjan Aug 5, 2023
17ae7f7
Update components/account/manage/Navigation.js
eddiejaoude Aug 6, 2023
326a215
Update components/user/UserEvents.js
eddiejaoude Aug 6, 2023
35014f6
Update components/user/UserEvents.js
eddiejaoude Aug 6, 2023
60a552c
Update components/user/UserEvents.js
eddiejaoude Aug 6, 2023
60e81d9
Update components/Tabs.js
eddiejaoude Aug 6, 2023
083568e
Update components/Tabs.js
eddiejaoude Aug 6, 2023
94bbf42
Update components/form/Select.js
eddiejaoude Aug 6, 2023
ca95eec
Update components/user/UserEvents.js
eddiejaoude Aug 6, 2023
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
18 changes: 6 additions & 12 deletions components/Tabs.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Link from "@components/Link";
import Select from "@components/form/Select";
import { classNames } from "utils/functions/classNames";

export default function Tabs({ tabs, setTabs }) {
const changeTab = (e, value) => {
e.preventDefault();
Expand All @@ -16,21 +16,15 @@ export default function Tabs({ tabs, setTabs }) {
return (
<div>
<div className="sm:hidden">
<label htmlFor="tabs" className="sr-only">
Select a tab
</label>
{tabs.length > 1 && (
<select
<Select
id="tabs"
name="tabs"
value={tabs.find((tab) => tab.current).name}
label="Select a tab"
onChange={changeTab}
className="block w-full rounded-md border-primary-medium-low dark:bg-primary-medium focus:border-secondary-medium focus:ring-secondary-medium"
defaultValue={tabs.find((tab) => tab.current).name}
>
{tabs.map((tab) => (
<option key={tab.name}>{tab.name}</option>
))}
</select>
options={tabs.map((tab) => ({ label: tab.name, value: tab.name }))}
/>
)}
</div>
<div className="hidden sm:block">
Expand Down
18 changes: 6 additions & 12 deletions components/event/EventTabs.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Link from "@components/Link";
import Select from "@components/form/Select";
import { classNames } from "utils/functions/classNames";

export function EventTabs({ tabs, eventType, setEventType }) {
const changeTab = (e, value) => {
e.preventDefault();
Expand All @@ -13,20 +13,14 @@ export function EventTabs({ tabs, eventType, setEventType }) {
return (
<div>
<div className="sm:hidden">
<label htmlFor="tabs" className="sr-only">
Select a tab
</label>
<select
<Select
id="tabs"
name="tabs"
label="Select a tab"
value={tabs.find((tab) => tab.key === eventType)?.title}
onChange={(e) => changeTab(e)}
className="block w-full rounded-md border-primary-medium-low dark:bg-primary-medium dark:focus:border-secondary-low dark:focus:ring-secondary-low focus:border-secondary-low focus:ring-secondary-low"
defaultValue={tabs.find((tab) => tab.key === eventType)?.title}
>
{tabs.map((tab) => (
<option key={tab.key}>{tab.title}</option>
))}
</select>
options={tabs.map((tab) => ({ label: tab.title, value: tab.title }))}
/>
</div>
<div className="hidden sm:block">
<div className="border-b border-primary-low">
Expand Down
26 changes: 0 additions & 26 deletions components/form/DropDown.js

This file was deleted.

27 changes: 18 additions & 9 deletions components/form/Select.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,35 @@
export default function Select({
name,
value,
label,
onChange,
options = [],
label,
className,
...restProps
}) {
return (
<>
{label && (
<label htmlFor={name} className="mt-4 mb-3">
<label htmlFor={value} className={`sr-only ${className}`}>
{label}
</label>
)}
<select
id={name}
name={name}
className="mt-2 text-primary-high dark:bg-primary-high dark:text-white border-2 transition-all duration-250 ease-linear rounded px-6 py-2 mb-2 block w-full sm:text-sm sm:leading-6"
defaultValue={value}
id={value}
value={value}
onChange={onChange}
className={`mt-2 text-primary-high dark:bg-primary-high dark:text-white border-2 transition-all duration-250 ease-linear rounded px-6 py-2 mb-2 block w-full sm:text-sm sm:leading-6 ${
restProps.className || ""
}`}
{...restProps}
>
{options.map((v) => (
<option key={v} className="checked:text-secondary-high checked:font-bold dark:checked:text-secondary-low-high">{v}</option>
{options.map((option) => (
<option
className="checked:text-secondary-high checked:font-bold dark:checked:text-secondary-low-high"
key={option.value}
value={option.value}
>
{option.label || option}
</option>
))}
</select>
</>
Expand Down
14 changes: 6 additions & 8 deletions components/navbar/SubNav.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Link from "@components/Link";
import Select from "@components/form/Select";
import Router, { useRouter } from "next/router";
import { classNames } from "utils/functions/classNames";

Expand All @@ -20,21 +21,18 @@ export default function SubNav({ tabs }) {
<label htmlFor="tabs" className="sr-only">
Select a tab
</label>
<select
<Select
id="tabs"
name="tabs"
value={tabs.find((tab) => tab.current).name}
label="Select a tab"
options={tabs.map((tab) => ({ label: tab.name, value: tab.name }))}
className="block w-full rounded-md
border-primary-low-medium/30 dark:border-primary-low-medium
dark:text-primary-low
dark:bg-primary-medium
focus:border-secondary-medium-low focus:ring-secondary-medium-low"
defaultValue={tabs.find((tab) => tab.current).name}
onChange={changeTab}
>
{tabs.map((tab) => (
<option key={tab.name}>{tab.name}</option>
))}
</select>
/>
</div>
<div className="hidden sm:block">
<div className="border-b border-primary-low-medium/30">
Expand Down
29 changes: 16 additions & 13 deletions components/user/UserEvents.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useState } from "react";
import EventCard from "@components/event/EventCard";
import Alert from "@components/Alert";
import DropdownMenu from "@components/form/DropDown";
import Select from "@components/form/Select";

export default function UserEvents({
manage = false,
Expand All @@ -21,7 +21,6 @@ export default function UserEvents({
{ value: "paid", name: "Paid Events" },
{ value: "past", name: "Past Events" },
];

const handleEventTypeChange = (event) => {
setEventType(event.target.value);
};
Expand Down Expand Up @@ -54,9 +53,7 @@ export default function UserEvents({
}
return events.filter((event) => filterByEventType(event, eventType));
};

const eventsToShow = getFilteredEvents();

const filteredEventOptions = eventOptions.filter((option) => {
if (option.value === "all") {
return true;
Expand All @@ -69,18 +66,24 @@ export default function UserEvents({

return (
<>
{!eventsToShow?.length && <Alert type="info" message="No Events found" />}

{eventsToShow.length === 0 && !manage && (
<Alert type="info" message="No Events found" />
)}

{!manage && (
<DropdownMenu
eventType={eventType}
handleEventTypeChange={handleEventTypeChange}
options={filteredEventOptions}
label="Select Event Type:"
className="inline text-center text-sm font-medium leading-6 text-primary-high sm:pt-1.5 dark:text-primary-low"

eddiejaoude marked this conversation as resolved.
Show resolved Hide resolved
<Select
id="event-type"
value={eventType}
label="Select an event type"
onChange={handleEventTypeChange}
options={filteredEventOptions.map((option) => ({
label: option.name,
value: option.value,
}))}
className="inline text-center text-sm font-medium leading-6 text-primary-high sm:pt-1.5"
/>
)}

{eventsToShow.length > 0 && (
<ul role="list" className="mt-4">
{eventsToShow.map((event, index) => (
Expand Down
2 changes: 1 addition & 1 deletion pages/account/manage/milestone/[[...data]].js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export default function ManageMilestone({ BASE_URL, milestone }) {
return (
<>
<PageHead
title="Manage Milstone"
title="Manage Milestone"
description="Here you can manage your LinkFree milestone"
/>

Expand Down
8 changes: 4 additions & 4 deletions stories/components/form/DropDown.stories.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import DropDown from "@components/form/DropDown";
import Select from "@components/form/Select";

export default {
component: DropDown
component: Select
};

const options = [
Expand All @@ -13,10 +13,10 @@ const options = [

export const Basic = {
args: {
eventType: 3,
value: 3,
label: 'Test',
options: options,
handleEventTypeChange: (e) => console.log(e.target.value),
onChange: (e) => console.log(e.target.value),
className: ''
}
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The DropDown.stories.js file should be renamed to Select.stories.js to match the component

2 changes: 1 addition & 1 deletion tests/events.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ test("Click on events profile in navbar navigates to events page", async ({
.getByRole("navigation")
.getByRole("link", { name: "Events" })
.click();
await expect(page).toHaveURL("/events");
await expect(page).toHaveURL(/\/events/);
});

test("Events has title", async ({ page }) => {
Expand Down