diff --git a/frontend/src/components/CardsTable.tsx b/frontend/src/components/CardsTable.tsx index e7b2ec64..e4d84e0c 100644 --- a/frontend/src/components/CardsTable.tsx +++ b/frontend/src/components/CardsTable.tsx @@ -197,7 +197,7 @@ export const CardsTable = ({ )} - diff --git a/frontend/src/main.tsx b/frontend/src/main.tsx index 6ae6c473..272f6e76 100644 --- a/frontend/src/main.tsx +++ b/frontend/src/main.tsx @@ -56,11 +56,11 @@ const router = createBrowserRouter([ element: , }, { - path: '/cards/detail', + path: '/cards/detail/:id', element: , }, { - path: '/cards/settings', + path: '/cards/:id/settings', element: , }, ]); diff --git a/frontend/src/pages/Login.tsx b/frontend/src/pages/Login.tsx index e355c1f9..a2f9ba43 100644 --- a/frontend/src/pages/Login.tsx +++ b/frontend/src/pages/Login.tsx @@ -3,7 +3,10 @@ import { Box, Button, Container, - Flex, + Alert, + AlertIcon, + AlertTitle, + AlertDescription, FormControl, FormLabel, Heading, @@ -53,6 +56,7 @@ export const LoginPage = () => { const [city, setCity] = useState('Berlin'); const [countryCode, setCountryCode] = useState('DE'); const [poBox, setPoBox] = useState('10212'); + const [errors, setErrors] = useState([]); useEffect(() => { if (accessToken !== '') { @@ -119,19 +123,32 @@ export const LoginPage = () => { }; const signUp = async (data: any) => { - const res = await api.post('/user', JSON.stringify(data)); - console.log(res); - const user = await res.data; - console.log(user); - console.log(res.status); - console.log(res); + try { + const res = await api.post('/user', JSON.stringify(data)); + if (res?.response.data.statusCode === 400) { + setErrors(res?.response.data.message) + } else if(res?.response.data.statusCode === 201){ + const user = await res?.data; + console.log(user); + console.log(res?.status); + } else { + setErrors(["The error is from our end... We're trying to resolve it as soon as possible"]) + } + } catch(e) { + console.log(e); + } }; + console.log(typeof(errors)); + + + return ( <> { + { + errors.length > 0 && + + + {/* Error! */} + + {Array.isArray(errors) ? ( + // Render multiple messages +
    + {errors.map((msg, index) => ( + {msg} + ))} +
+ ) : ( + // Render a single message +

{errors}

+ )} +
+
+ }
{ e.preventDefault(); diff --git a/frontend/src/pages/auth/CardDetail.tsx b/frontend/src/pages/auth/CardDetail.tsx index 2c4bab7c..df8b4369 100644 --- a/frontend/src/pages/auth/CardDetail.tsx +++ b/frontend/src/pages/auth/CardDetail.tsx @@ -1,27 +1,57 @@ -import { Box, Button } from '@chakra-ui/react'; -import { useContext } from 'react'; +import { Box, Button, Spinner, Text } from '@chakra-ui/react'; +import { useContext, useEffect, useState } from 'react'; import AuthRootPage from './AuthRoot'; import { TransactionsTable } from '../../components/TransactionsTable'; import { AppContext } from '../../context'; +import { useParams } from 'react-router-dom'; +import api from '../../utils/axios.interceptor'; +import { LoadingView } from '../../components/LoadingView'; + +interface ICardDetail { + brand: string, + cardId: string, + cardholderId: string, + currency: string, + expMonth: string, + expYear: string, + last4: string, + status: string, + type: string, + id: string +} const CardDetailPage = () => { const { accessToken } = useContext(AppContext); + const route = useParams() + const [CardDetail, setCardDetail] = useState() + + useEffect( () => { + load() + }, []) + + const load = async () => { + const res = await api.get(`/card/get/${route.id}`); + setCardDetail(res.data) + } return ( + } > - + { + CardDetail ? + <> + @@ -30,15 +60,22 @@ const CardDetailPage = () => { src="https://raw.githubusercontent.com/muhammederdem/credit-card-form/master/src/assets/images/chip.png" alt="" /> -

1234 **** **** 0987

+

**** **** **** {CardDetail.last4}

-

08/26

-

Daniel Lite

+

{CardDetail.expMonth}/{CardDetail.expYear}

+ {/*

Daniel Lite

*/}
+ + : + + + Loading card data... + + }
); }; diff --git a/frontend/src/pages/auth/CardSettings.tsx b/frontend/src/pages/auth/CardSettings.tsx index 07915667..9ca5b633 100644 --- a/frontend/src/pages/auth/CardSettings.tsx +++ b/frontend/src/pages/auth/CardSettings.tsx @@ -18,18 +18,21 @@ import PaymentCard from '../../components/PaymentCard'; import { AppContext } from '../../context'; import api from '../../utils/axios.interceptor'; import { handleResponse } from '../../utils/response-helper'; +import { useParams } from 'react-router-dom'; const CardSettingsPage = () => { const toast = useToast(); - const cardId = '65672eec595c1dc89f5271b5'; const { accessToken } = useContext(AppContext); const [card, setCard] = useState(); const [singleTxLimit, setSingleTxLimit] = useState(1000); const [monthlyLimit, setMonthlyLimit] = useState(5000); + const route = useParams() + + useEffect(() => { const load = async () => { - const res = await api.get(`http://localhost:3000/card/get/${cardId}`); + const res = await api.get(`/card/get/${route.id}`); const card = await res.data; setCard(card); console.log('card', card); @@ -41,18 +44,12 @@ const CardSettingsPage = () => { const handleSubmit = async (event: React.FormEvent) => { event.preventDefault(); - const res = await fetch(`http://localhost:3000/card/limits`, { - method: 'PUT', - headers: { - 'Content-Type': 'application/json', - Authorization: `Bearer ${accessToken}`, - }, - body: JSON.stringify({ - cardId, + const res = await api.put(`/card/limits`, JSON.stringify({ + cardId: card.cardId, monthlyLimit, singleTxLimit, }), - }); + ); await handleResponse( res, diff --git a/frontend/src/utils/axios.interceptor.ts b/frontend/src/utils/axios.interceptor.ts index 74a0ad0a..e78630bf 100644 --- a/frontend/src/utils/axios.interceptor.ts +++ b/frontend/src/utils/axios.interceptor.ts @@ -4,7 +4,7 @@ import { redirect } from 'react-router-dom'; const api = axios.create({ baseURL: 'http://localhost:3000', // our API base URL }); - +console.log() api.interceptors.request.use( (config) => { const token = localStorage.getItem('accessToken'); @@ -25,11 +25,11 @@ api.interceptors.response.use( }, function (error) { - console.log('Error', error); - if (error.response.status === 401) { + if (error.response.status === 401 && window.location.pathname !== '/login') { window.location.replace('/login'); return Promise.reject(error); - } + } + return error; }, );