Skip to content

Commit

Permalink
more type issues
Browse files Browse the repository at this point in the history
  • Loading branch information
dcantatore committed Jan 2, 2025
1 parent a1d9e4e commit 568e632
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 8 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-rrule-builder-ts",
"version": "0.0.20",
"version": "0.0.21",
"description": "rrule component for react with mui",
"main": "index.js",
"scripts": {
Expand Down Expand Up @@ -31,6 +31,7 @@
"@mui/material": "^6.3.0",
"@mui/x-date-pickers": "^7.23.3",
"lodash": "^4.17.21",
"luxon": "^3.5.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"rrule": "^2.8.1",
Expand All @@ -51,6 +52,7 @@
"@storybook/react": "^8.2.9",
"@storybook/react-vite": "^8.2.9",
"@storybook/test": "^8.2.9",
"@types/luxon": "^3.4.2",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"@typescript-eslint/eslint-plugin": "^7.0.0",
Expand Down
9 changes: 6 additions & 3 deletions src/components/RRuleBuilder/RRuleBuilder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { LocalizationProvider, MuiPickersAdapter, PickersTimezone } from "@mui/x
import { Frequency } from "rrule";
import { useTheme } from "@mui/material/styles";
import { TextFieldProps } from "@mui/material/TextField";
import { DateTime } from "luxon";
import RepeatSelect from "../Repeat/Repeat";
import useBuilderStore from "../../store/builderStore";
import End from "../End/End";
Expand All @@ -16,9 +17,11 @@ type Lang = {
endDatePickerLabel: string;
};

type MuiPickersAdapterConstructor<TDate> = new (...args: any[]) => MuiPickersAdapter<TDate>;
type MuiPickersAdapterConstructor<TDate extends DateTime<boolean>> = new (
...args: any[]
) => MuiPickersAdapter<TDate>;

interface RRuleBuilderProps<TDate> {
interface RRuleBuilderProps<TDate extends DateTime<boolean>> {
dateAdapter: MuiPickersAdapterConstructor<TDate>;
datePickerInitialDate?: TDate;
onChange?: (rruleString: string) => void;
Expand All @@ -37,7 +40,7 @@ interface RRuleBuilderProps<TDate> {
}

// eslint-disable-next-line @typescript-eslint/comma-dangle
const RRuleBuilder = <TDate,>({
const RRuleBuilder = <TDate extends DateTime<boolean>,>({
datePickerInitialDate,
onChange,
rruleString,
Expand Down
5 changes: 3 additions & 2 deletions src/store/builderStore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import { WeekdayStr } from "rrule/dist/esm/weekday";
import isNil from "lodash/isNil";

import { MuiPickersAdapter } from "@mui/x-date-pickers";
import { DateTime } from "luxon";
import {
AllRepeatDetails, MonthBy, Weekday, YearlyBy,
} from "../components/Repeat/Repeat.types";
import getValidationSchema from "../validation/validationSchema";
import { EndDetails, EndType } from "../components/End/End.types";
import { buildRRuleString } from "../utils/buildRRuleString";

interface BuilderState<TDate> {
interface BuilderState<TDate extends DateTime<boolean>> {
repeatDetails: AllRepeatDetails;
frequency: Frequency;
startDate: TDate | null;
Expand All @@ -24,7 +25,7 @@ interface BuilderState<TDate> {
minEndDate?: TDate;
}

interface BuilderActions<TDate> {
interface BuilderActions<TDate extends DateTime<boolean>> {
validationErrors: Record<string, string>;
setAdapter: (dateAdapter: MuiPickersAdapter<TDate>) => void;
setFrequency: (frequency: Frequency) => void;
Expand Down
7 changes: 5 additions & 2 deletions src/utils/buildRRuleString.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import { RRule, Frequency, Options } from "rrule";
import { MuiPickersAdapter } from "@mui/x-date-pickers";
import { DateTime } from "luxon";
import { AllRepeatDetails } from "../components/Repeat/Repeat.types";
import { EndDetails, EndType } from "../components/End/End.types";

export interface BuildRRuleStringParams<TDate> {
export interface BuildRRuleStringParams<TDate extends DateTime<boolean>> {
frequency: Frequency;
startDate: TDate | null;
repeatDetails: AllRepeatDetails;
endDetails: EndDetails<TDate>;
dateAdapter: MuiPickersAdapter<TDate>;
}

export const buildRRuleString = (options: BuildRRuleStringParams<MuiPickersAdapter<any>>): string => {
export const buildRRuleString = <TDate extends DateTime<boolean>>(
options: BuildRRuleStringParams<TDate>,
): string => {
const {
frequency, startDate, repeatDetails, endDetails, dateAdapter,
} = options;
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2351,6 +2351,11 @@
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.17.5.tgz#e6c29b58e66995d57cd170ce3e2a61926d55ee04"
integrity sha512-MBIOHVZqVqgfro1euRDWX7OO0fBVUUMrN6Pwm8LQsz8cWhEpihlvR70ENj3f40j58TNxZaWv2ndSkInykNBBJw==

"@types/luxon@^3.4.2":
version "3.4.2"
resolved "https://registry.yarnpkg.com/@types/luxon/-/luxon-3.4.2.tgz#e4fc7214a420173cea47739c33cdf10874694db7"
integrity sha512-TifLZlFudklWlMBfhubvgqTXRzLDI5pCbGa4P8a3wPyUQSW+1xQ5eDsreP9DWHX3tjq1ke96uYG/nwundroWcA==

"@types/mdx@^2.0.0":
version "2.0.13"
resolved "https://registry.yarnpkg.com/@types/mdx/-/mdx-2.0.13.tgz#68f6877043d377092890ff5b298152b0a21671bd"
Expand Down

0 comments on commit 568e632

Please sign in to comment.