Skip to content

Commit

Permalink
minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
meetulr committed Mar 16, 2024
1 parent ed02889 commit 8ad6974
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 74 deletions.
48 changes: 1 addition & 47 deletions src/screens/OrganizationEvents/OrganizationEvents.test.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import React from 'react';
import { MockedProvider } from '@apollo/react-testing';
import {
act,
render,
screen,
fireEvent,
waitFor,
} from '@testing-library/react';
import { act, render, screen, fireEvent } from '@testing-library/react';
import { Provider } from 'react-redux';
import { BrowserRouter } from 'react-router-dom';
import 'jest-location-mock';
Expand Down Expand Up @@ -456,44 +450,4 @@ describe('Organisation Events Page', () => {

userEvent.click(screen.getByTestId('createEventBtn'));
});

// test('Testing toggling of custom recurrence modal', async () => {
// render(
// <MockedProvider addTypename={false} link={link}>
// <BrowserRouter>
// <Provider store={store}>
// <LocalizationProvider dateAdapter={AdapterDayjs}>
// <ThemeProvider theme={theme}>
// <I18nextProvider i18n={i18nForTest}>
// <OrganizationEvents />
// </I18nextProvider>
// </ThemeProvider>
// </LocalizationProvider>
// </Provider>
// </BrowserRouter>
// </MockedProvider>,
// );

// await wait();

// await waitFor(() => {
// expect(screen.getByTestId('recurringCheck')).toBeInTheDocument();
// });

// userEvent.click(screen.getByTestId('recurringCheck'));

// await waitFor(() => {
// expect(
// screen.getByTestId('customRecurrenceModalCloseBtn'),
// ).toBeInTheDocument();
// });

// userEvent.click(screen.getByTestId('customRecurrenceModalCloseBtn'));

// await waitFor(() => {
// expect(
// screen.queryByTestId('customRecurrenceModalCloseBtn'),
// ).not.toBeInTheDocument();
// });
// });
});
43 changes: 18 additions & 25 deletions src/screens/OrganizationEvents/OrganizationEvents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function organizationEvents(): JSX.Element {
const [customRecurrenceModalIsOpen, setCustomRecurrenceModalIsOpen] =
useState<boolean>(false);

const [startDate, setStartDate] = React.useState<Date | null>(new Date());
const [startDate, setStartDate] = React.useState<Date>(new Date());
const [endDate, setEndDate] = React.useState<Date | null>(new Date());

const [alldaychecked, setAllDayChecked] = React.useState(true);
Expand All @@ -53,11 +53,10 @@ function organizationEvents(): JSX.Element {
const [publicchecked, setPublicChecked] = React.useState(true);
const [registrablechecked, setRegistrableChecked] = React.useState(false);

const currentDay = new Date().getDay();
const [recurrenceRuleState, setRecurrenceRuleState] =
useState<InterfaceRecurrenceRule>({
frequency: Frequency.WEEKLY,
weekDays: [Days[currentDay]],
weekDays: [Days[startDate.getDay()]],
count: undefined,
});

Expand Down Expand Up @@ -107,7 +106,7 @@ function organizationEvents(): JSX.Element {
const { frequency, weekDays, count } = recurrenceRuleState;
const recurrenceRuleText = getRecurrenceRuleText(
recurrenceRuleState,
startDate as Date,
startDate,
endDate,
);

Expand Down Expand Up @@ -156,7 +155,7 @@ function organizationEvents(): JSX.Element {
setRecurringChecked(false);
setRecurrenceRuleState({
frequency: Frequency.WEEKLY,
weekDays: [Days[currentDay]],
weekDays: [Days[new Date().getDay()]],
count: undefined,
});
setStartDate(new Date());
Expand Down Expand Up @@ -184,10 +183,6 @@ function organizationEvents(): JSX.Element {
}
}, [error]);

useEffect(() => {
console.log(recurrenceRuleState);
}, [recurrenceRuleState]);

if (loading || loading2) {
return <Loader />;
}
Expand Down Expand Up @@ -295,6 +290,10 @@ function organizationEvents(): JSX.Element {
endDate &&
(endDate < date?.toDate() ? date?.toDate() : endDate),
);
setRecurrenceRuleState({
...recurrenceRuleState,
weekDays: [Days[date?.toDate().getDay()]],
});
}
}}
/>
Expand Down Expand Up @@ -409,8 +408,8 @@ function organizationEvents(): JSX.Element {
{recurringchecked && (
<Dropdown drop="up" className="mt-2 d-inline-block w-100">
<Dropdown.Toggle
className="py-2"
variant="outline-secondary"
className="py-2 border border-secondary-subtle rounded-2"
id="dropdown-basic"
>
{recurrenceRuleText.length > 45 ? (
Expand All @@ -427,13 +426,7 @@ function organizationEvents(): JSX.Element {
</span>
</OverlayTrigger>
) : (
<span className="fw-semibold">
{getRecurrenceRuleText(
recurrenceRuleState,
startDate as Date,
endDate,
)}
</span>
<span className="fw-semibold">{recurrenceRuleText}</span>
)}
</Dropdown.Toggle>

Expand All @@ -449,10 +442,10 @@ function organizationEvents(): JSX.Element {
{getRecurrenceRuleText(
{
frequency: Frequency.DAILY,
weekDays: [],
weekDays,
count,
},
startDate as Date,
startDate,
endDate,
)}
</Dropdown.Item>
Expand All @@ -467,10 +460,10 @@ function organizationEvents(): JSX.Element {
{getRecurrenceRuleText(
{
frequency: Frequency.WEEKLY,
weekDays: [Days[currentDay]],
weekDays: [Days[startDate.getDay()]],
count,
},
startDate as Date,
startDate,
endDate,
)}
</Dropdown.Item>
Expand All @@ -485,10 +478,10 @@ function organizationEvents(): JSX.Element {
{getRecurrenceRuleText(
{
frequency: Frequency.MONTHLY,
weekDays: [Days[currentDay]],
weekDays,
count,
},
startDate as Date,
startDate,
endDate,
)}
</Dropdown.Item>
Expand All @@ -503,10 +496,10 @@ function organizationEvents(): JSX.Element {
{getRecurrenceRuleText(
{
frequency: Frequency.YEARLY,
weekDays: [Days[currentDay]],
weekDays,
count,
},
startDate as Date,
startDate,
endDate,
)}
</Dropdown.Item>
Expand Down
4 changes: 2 additions & 2 deletions src/screens/OrganizationEvents/customRecurrenceModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type {
import type { Dayjs } from 'dayjs';
import dayjs from 'dayjs';

interface InterfaceCustomRecurrenceProps {
interface InterfaceCustomRecurrenceModalProps {
recurrenceRuleState: InterfaceRecurrenceRule;
setRecurrenceRuleState: (
state: React.SetStateAction<InterfaceRecurrenceRule>,
Expand All @@ -25,7 +25,7 @@ interface InterfaceCustomRecurrenceProps {
t: (key: string) => string;
}

const CustomRecurrenceModal: React.FC<InterfaceCustomRecurrenceProps> = ({
const CustomRecurrenceModal: React.FC<InterfaceCustomRecurrenceModalProps> = ({
recurrenceRuleState,
setRecurrenceRuleState,
endDate,
Expand Down

0 comments on commit 8ad6974

Please sign in to comment.