Skip to content
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

Dev ts redux #169

Merged
merged 2 commits into from
Sep 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
46 changes: 29 additions & 17 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
"@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"@types/jest": "^29.5.13",
"@types/node": "^22.5.5",
"@types/react": "^18.3.8",
"@types/react-dom": "^18.3.0",
"ag-grid-react": "^31.3.1",
"apexcharts": "^3.44.0",
"dayjs": "^1.11.11",
Expand All @@ -44,6 +48,7 @@
"rsuite": "^5.64.1",
"sass": "^1.66.1",
"styled-components": "^6.1.11",
"typescript": "^5.6.2",
"web-vitals": "^2.1.4"
},
"scripts": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import { ReactNode } from "react";

// nutrition tracker types

export interface NutritionTrackedDayContextType {
nutritionTrackedDays: NutritionTrackedDay[];
formInputMicronutrients: FormInputMicronutrient[];
selectedNutritionTrackedDay: SelectedNutritionTrackedDay;
filterConditions: FilterConditions;
nutritionTrackedDaysView: NutritionTrackedDaysView;
scheduledNutritionTrackedDaysView: ScheduledNutritionTrackedDaysView;

addDayTracked: (trackedDayInfo: NutritionTrackedDay) => void;
updateDayTracked: (updatedTrackedDayInfo: NutritionTrackedDay) => void;
getDayTracked: (trackedDay: string | Date) => void;

selectedScheduledNutritionTrackedDay: (trackedDay: string | Date) => void;

dayTrackedSearchResult: NutritionTrackedDay;

addFormInputMicronutrients: () => void;
updateFormInputMicronutrients: (micronutrient: Micronutrient, micronutrientIndex: number) => void;
deleteFormInputMicronutrients: (micronutrientIndex: number) => void;

addDayTrackedFromPrediction: (predictionNutritionInfo: PredictionNutritionInfo) => void;

nutritionTrackedDaysSummary: NutritionTrackedDaysSummary;

filterDayTracked: (filterConditions: FilterConditions) => void;
removeDayTracked: (trackedDay: string | Date) => void;
clearDayTrackedFilter: () => void;
}

export interface NutritionTrackedDayProviderProps {
children: ReactNode
}

export type NutritionTrackedDay = {
dateTracked: string;
calories: number;
macronutrients: Macronutrient[];
micronutrients: Micronutrient[];
}

export type Macronutrient = {
carbohydrates: number;
protein: number;
fat: number;
}

export type Micronutrient = {
name: string;
amount: number;
unit: string;
}

export type FormInputMicronutrient = {
name: string;
amount: number;
unit: string;
}

export type SelectedNutritionTrackedDay = string | Date | null;

export type FilterConditions = {
filterStartDate?: string;
filterEndDate?: string;
}

export type NutritionTrackedDaysView = NutritionTrackedDay[];

export type ScheduledNutritionTrackedDaysView = NutritionTrackedDay

export type DayTrackedSearchResult = NutritionTrackedDay;

export type NutritionTrackedDaysSummary = {
averageDailyCaloriesConsumption: number;
averageDailyCarbohydratesConsumption: number;
averageDailyProteinConsumption: number;
averageDailyFatConsumption: number;
}

export type PredictionNutritionInfo = {
dateTracked: string | Date;
calories: number;
macronutrients: Macronutrient[];
micronutrients: Micronutrient[];
}
6 changes: 6 additions & 0 deletions src/custom.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
declare module "*.svg" {
import React = require("react")
export const ReactComponent: React.FC<React.SVGProps<SVGSVGElement>>
const src: string;
export default src;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// redux middlewares

export const loggerMiddleware = (store) => (next) => (action) => {
import { Middleware } from "redux"
import { RootState } from "../store"

export const loggerMiddleware: Middleware<{}, RootState> = (store) => (next) => (action: any) => {
if (!action.type) {
return next(action)
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
26 changes: 0 additions & 26 deletions src/store/shared/user/user.action.js

This file was deleted.

68 changes: 68 additions & 0 deletions src/store/shared/user/user.action.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { User } from "firebase/auth";
import { AdditionalInformation, UserData } from "../../../utils/firebase/firebase.utils";
import { Action, ActionWithPayload, createAction, withMatcher } from "../../../utils/reducer/reducer.utils";
import { USER_ACTION_TYPES } from "./user.types"

export type CheckUserSession = Action<USER_ACTION_TYPES.CHECK_USER_SESSION>
export type SetCurrentUser = ActionWithPayload<USER_ACTION_TYPES.SET_CURRENT_USER, UserData>
export type GoogleSignInStart = Action<USER_ACTION_TYPES.GOOGLE_SIGN_IN_START>
export type EmailSignInStart = ActionWithPayload<USER_ACTION_TYPES.EMAIL_SIGN_IN_START, { email: string, password: string }>
export type SignInSuccess = ActionWithPayload<USER_ACTION_TYPES.SIGN_IN_SUCCESS, UserData>
export type SignInFailed = ActionWithPayload<USER_ACTION_TYPES.SIGN_IN_FAILED, Error>
export type SignUpStart = ActionWithPayload<USER_ACTION_TYPES.SIGN_UP_START, { email: string, password: string, displayName: string }>
export type SignUpSuccess = ActionWithPayload<USER_ACTION_TYPES.SIGN_UP_SUCCESS, { user: User, additionalDetails: AdditionalInformation }>
export type SignUpFailed = ActionWithPayload<USER_ACTION_TYPES.SIGN_UP_FAILED, Error>
export type SignOutStart = Action<USER_ACTION_TYPES.SIGN_OUT_START>
export type SignOutSuccess = Action<USER_ACTION_TYPES.SIGN_OUT_SUCCESS>
export type SignOutFailed = ActionWithPayload<USER_ACTION_TYPES.SIGN_OUT_FAILED, Error>

export const setCurrentUser = withMatcher((user: UserData): SetCurrentUser => createAction(USER_ACTION_TYPES.SET_CURRENT_USER, user))

export const checkUserSession = withMatcher((): CheckUserSession => createAction(USER_ACTION_TYPES.CHECK_USER_SESSION))

export const googleSignInStart = withMatcher((): GoogleSignInStart => createAction(USER_ACTION_TYPES.GOOGLE_SIGN_IN_START))

export const emailSignInStart = withMatcher((email: string, password: string): EmailSignInStart => createAction(USER_ACTION_TYPES.EMAIL_SIGN_IN_START, { email, password }))

export const signInSuccess = withMatcher((user: UserData): SignInSuccess => createAction(USER_ACTION_TYPES.SIGN_IN_SUCCESS, user))

export const signInFailed = withMatcher((error: Error): SignInFailed => createAction(USER_ACTION_TYPES.SIGN_IN_FAILED, error))

export const signUpStart = withMatcher((email: string, password: string, displayName: string): SignUpStart => createAction(USER_ACTION_TYPES.SIGN_UP_START, { email, password, displayName }))

export const signUpSuccess = withMatcher((user: User, additionalDetails: AdditionalInformation): SignUpSuccess => createAction(USER_ACTION_TYPES.SIGN_UP_SUCCESS, { user, additionalDetails }))

export const signUpFailed = withMatcher((error: Error): SignUpFailed => createAction(USER_ACTION_TYPES.SIGN_UP_FAILED, error))

export const signOutStart = withMatcher((): SignOutStart => createAction(USER_ACTION_TYPES.SIGN_OUT_START))

export const signOutSuccess = withMatcher((): SignOutSuccess => createAction(USER_ACTION_TYPES.SIGN_OUT_SUCCESS))

export const signOutFailed = withMatcher((error: Error): SignOutFailed => createAction(USER_ACTION_TYPES.SIGN_OUT_FAILED, error))

// import { createAction } from "../../../utils/reducer/reducer.utils";
// import { USER_ACTION_TYPES } from "./user.types"

// export const setCurrentUser = (user) => createAction(USER_ACTION_TYPES.SET_CURRENT_USER, user)

// export const checkUserSession = () => createAction(USER_ACTION_TYPES.CHECK_USER_SESSION)

// export const googleSignInStart = () => createAction(USER_ACTION_TYPES.GOOGLE_SIGN_IN_START)

// export const emailSignInStart = (email, password) => createAction(USER_ACTION_TYPES.EMAIL_SIGN_IN_START, { email, password })

// export const signInSuccess = (user) => createAction(USER_ACTION_TYPES.SIGN_IN_SUCCESS, user)

// export const signInFailed = (error) => createAction(USER_ACTION_TYPES.SIGN_IN_FAILED, error)

// export const signUpStart = (email, password, displayName) => createAction(USER_ACTION_TYPES.SIGN_UP_START, { email, password, displayName })

// export const signUpSuccess = (user, additionalDetails) => createAction(USER_ACTION_TYPES.SIGN_UP_SUCCESS, { user, additionalDetails })

// export const signUpFailed = (error) => createAction(USER_ACTION_TYPES.SIGN_UP_FAILED, error)

// export const signOutStart = () => createAction(USER_ACTION_TYPES.SIGN_OUT_START)

// export const signOutSuccess = () => createAction(USER_ACTION_TYPES.SIGN_OUT_SUCCESS)

// export const signOutFailed = (error) => createAction(USER_ACTION_TYPES.SIGN_OUT_FAILED)
44 changes: 0 additions & 44 deletions src/store/shared/user/user.reducer.js

This file was deleted.

19 changes: 0 additions & 19 deletions src/store/shared/user/user.reducer.toolkit.js

This file was deleted.

Loading
Loading