diff --git a/package.json b/package.json
index 20a3c87..3f7562b 100644
--- a/package.json
+++ b/package.json
@@ -9,6 +9,11 @@
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
+ "@types/jest": "^29.2.5",
+ "@types/node": "^18.11.18",
+ "@types/react": "^18.0.26",
+ "@types/react-dom": "^18.0.10",
+ "@types/styled-components": "^5.1.26",
"dotenv": "^16.0.3",
"firebase": "^9.14.0",
"react": "^18.2.0",
@@ -22,6 +27,7 @@
"sass": "^1.56.1",
"stripe": "^11.5.0",
"styled-components": "^5.3.6",
+ "typescript": "^4.9.4",
"web-vitals": "^2.1.4"
},
"scripts": {
diff --git a/src/App.js b/src/App.js
index 4cfbbf5..5e26daf 100644
--- a/src/App.js
+++ b/src/App.js
@@ -14,9 +14,14 @@ const App = ()=> {
useEffect(() => {
const unsubscribe = onAuthStateChangeListener((user)=>{
+ const createUser = async (user) => {
+ const userSnapshot = await createUserDocumentFromAuth(user);
+ return userSnapshot;
+ };
if (user) {
- const userSnapshot = createUserDocumentFromAuth(user);
- dispatch(setUser(user)); // TODO: should be userSnapshot!
+ const userSnapshot = createUser(user);
+ console.log(userSnapshot);
+ dispatch(setUser(user)); // TODO: test and use userSnapshot!
}
});
diff --git a/src/components/button/button.component.jsx b/src/components/button/button.component.jsx
deleted file mode 100644
index a2dca5e..0000000
--- a/src/components/button/button.component.jsx
+++ /dev/null
@@ -1,14 +0,0 @@
-import { BaseButton, GoogleSignInButton, InvertedButton, SpinnerButton } from './button.sytles'
-
-const getButton = (buttonType = 'base') => ({
- base: BaseButton,
- google: GoogleSignInButton,
- inverted: InvertedButton,
-}[buttonType])
-
-const Button = ({ children, buttonType, isLoading, ...otherProps }) => {
- const CustomButton = getButton(buttonType);
- return {isLoading ? : children};
-};
-
-export default Button;
\ No newline at end of file
diff --git a/src/components/button/button.component.tsx b/src/components/button/button.component.tsx
new file mode 100644
index 0000000..e5f024e
--- /dev/null
+++ b/src/components/button/button.component.tsx
@@ -0,0 +1,26 @@
+import { ButtonHTMLAttributes, FC } from 'react';
+import { BaseButton, GoogleSignInButton, InvertedButton, SpinnerButton } from './button.sytles'
+
+export enum BUTTON_TYPES {
+ base = 'base',
+ google = 'google',
+ inverted = 'inverted',
+};
+
+const getButton = (buttonType = BUTTON_TYPES.base): typeof BaseButton => ({
+ [BUTTON_TYPES.base]: BaseButton,
+ [BUTTON_TYPES.google]: GoogleSignInButton,
+ [BUTTON_TYPES.inverted]: InvertedButton,
+}[buttonType])
+
+export type ButtonProps = {
+ buttonType?: BUTTON_TYPES,
+ isLoading?: boolean,
+} & ButtonHTMLAttributes;
+
+const Button: FC = ({ children, buttonType, isLoading, ...otherProps }) => {
+ const CustomButton = getButton(buttonType);
+ return {isLoading ? : children};
+};
+
+export default Button;
\ No newline at end of file
diff --git a/src/components/button/button.sytles.jsx b/src/components/button/button.sytles.tsx
similarity index 100%
rename from src/components/button/button.sytles.jsx
rename to src/components/button/button.sytles.tsx
diff --git a/src/components/payment-form/payment-form.component.jsx b/src/components/payment-form/payment-form.component.jsx
index 073307d..80bb956 100644
--- a/src/components/payment-form/payment-form.component.jsx
+++ b/src/components/payment-form/payment-form.component.jsx
@@ -1,7 +1,6 @@
import { useState } from 'react';
import { CardElement, useStripe, useElements } from '@stripe/react-stripe-js';
-import Button from '../button/button.component';
-import { PaymentFormContainer, FormContainer } from './payment-form.styles';
+import { PaymentFormContainer, FormContainer, PaymentButton } from './payment-form.styles';
import { useSelector } from 'react-redux';
const PaymentForm = () => {
@@ -52,13 +51,13 @@ const PaymentForm = () => {
Credit Card Payment:
-
+
)
diff --git a/src/components/payment-form/payment-form.styles.jsx b/src/components/payment-form/payment-form.styles.jsx
index ed63cff..c9ad222 100644
--- a/src/components/payment-form/payment-form.styles.jsx
+++ b/src/components/payment-form/payment-form.styles.jsx
@@ -1,4 +1,5 @@
import styled from "styled-components";
+import Button from "../button/button.component";
export const PaymentFormContainer = styled.div`
height: 300px;
@@ -12,3 +13,8 @@ export const FormContainer = styled.div`
height: 100px;
min-width: 500px;
`;
+
+export const PaymentButton = styled(Button)`
+ margin-left: auto;
+ margin-top: 30px;
+`
diff --git a/src/components/sign-in-form/sign-in-form.component.jsx b/src/components/sign-in-form/sign-in-form.component.jsx
index 62a51b2..1a8d6b9 100644
--- a/src/components/sign-in-form/sign-in-form.component.jsx
+++ b/src/components/sign-in-form/sign-in-form.component.jsx
@@ -2,7 +2,7 @@ import { useState } from 'react';
import { signInWithGooglePopup } from '../../utils/firebase/firebase.utils';
import { signInAuthUserWithEmailAndPassword } from '../../utils/firebase/firebase.utils';
import FormInput from '../../components/form-input/form-input.component';
-import Button from '../../components/button/button.component';
+import Button from '../button/button.component';
import { SignInContainer, ButtonContainer } from './sign-in-form.styles'
const defaultFormFields = {
@@ -66,8 +66,8 @@ const SignInForm = ()=> {
value={password}
/>
-
-
diff --git a/src/components/sign-up-form/sign-up-form.component.jsx b/src/components/sign-up-form/sign-up-form.component.jsx
index f010503..0dfb9f7 100644
--- a/src/components/sign-up-form/sign-up-form.component.jsx
+++ b/src/components/sign-up-form/sign-up-form.component.jsx
@@ -1,7 +1,7 @@
import { useState } from 'react';
import { createAuthUserWithEmailAndPassword } from '../../utils/firebase/firebase.utils';
import FormInput from '../../components/form-input/form-input.component';
-import Button from '../../components/button/button.component';
+import Button from '../button/button.component';
import { SignUpContainer } from './sign-up-form.styles';
const defaultFormFields = {
@@ -73,7 +73,7 @@ const SignUpForm = ()=> {
onChange={handleChange}
value={confirmPassword}
/>
- Sign Up
+ Sign Up
)
diff --git a/src/store/categories/categories.slice.js b/src/store/categories/categories.slice.ts
similarity index 61%
rename from src/store/categories/categories.slice.js
rename to src/store/categories/categories.slice.ts
index 2ac074c..61a71a1 100644
--- a/src/store/categories/categories.slice.js
+++ b/src/store/categories/categories.slice.ts
@@ -1,6 +1,14 @@
import { createSlice } from "@reduxjs/toolkit";
+import type { PayloadAction } from '@reduxjs/toolkit'
+import { RootState } from "../store";
-const InitCategoriesSate = {
+interface CategoriesState {
+ categoriesMap: Object | null,
+ isLoading: boolean,
+ error: Error | null,
+}
+
+const InitCategoriesSate: CategoriesState = {
categoriesMap: null,
isLoading: false,
error: null
@@ -15,12 +23,12 @@ export const categoriesSlice = createSlice({
state.error = null;
},
// getCategoriesSucceeded
- setCategories: (state, action) => {
+ setCategories: (state, action: PayloadAction