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

Client version #2

Draft
wants to merge 41 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
d1bf5af
Changes for client only version
MHMighani May 15, 2022
ef32882
Merge branch 'main' into client-version
MHMighani May 18, 2022
1565715
Changes for client only version
MHMighani May 18, 2022
1541681
Refactor
MHMighani May 19, 2022
69bdd0a
Merge branch 'main' into client-version
MHMighani May 19, 2022
60e4157
Refactor
MHMighani May 19, 2022
4c2233e
Merge branch 'main' into client-version
MHMighani May 19, 2022
d4d9d08
Changes for client version
MHMighani May 19, 2022
a972ede
Add build
MHMighani May 19, 2022
e728546
Remove server folder
MHMighani May 19, 2022
43c3b86
Update
MHMighani May 19, 2022
e8e7e23
Merge branch 'client-version' of github.com:MHMighani/chortkeh into c…
MHMighani May 19, 2022
54c72a2
Update
MHMighani May 19, 2022
19615c4
Fix:paths
MHMighani May 20, 2022
18670aa
Delete build folder
MHMighani May 20, 2022
29b075b
Merge branch 'main' into client-version
MHMighani May 21, 2022
8ea7481
Merge branch 'main' into client-version
MHMighani May 22, 2022
f6c12f2
Merge branch 'main' into client-version
MHMighani May 23, 2022
b9fb045
Add fake history builder
MHMighani May 23, 2022
feb5622
Merge branch 'main' into client-version
MHMighani May 23, 2022
6464793
Update gitignore
MHMighani May 23, 2022
ddfe7b0
Merge branch 'main' into client-version
MHMighani May 23, 2022
251b1d8
Add Opening modal
MHMighani May 23, 2022
accb268
Merge branch 'main' into client-version
MHMighani May 24, 2022
5d9fd67
Feat: portfolio overview
MHMighani May 24, 2022
3f08a7a
Merge branch 'main' into client-version
MHMighani May 24, 2022
835ffb3
Merge branch 'main' into client-version
MHMighani May 24, 2022
3db0e8e
Merge branch 'main' into client-version
MHMighani May 25, 2022
a0e05ca
Update home address
MHMighani May 25, 2022
2db75e6
Update opening modal text
MHMighani May 25, 2022
c393474
Merge branch 'main' into client-version
MHMighani May 25, 2022
08a892a
Fix: date for fake history
MHMighani May 25, 2022
980f0bc
Merge branch 'main' into client-version
MHMighani May 26, 2022
43123bc
Merge branch 'main' into client-version
MHMighani May 26, 2022
7871d41
Fix: fake overall history builder
MHMighani May 26, 2022
87aef3b
Update opening modal
MHMighani May 26, 2022
e63f8e2
Merge branch 'main' into client-version
MHMighani May 27, 2022
f3abfb5
Merge branch 'main' into client-version
MHMighani May 27, 2022
7f27513
Fix: crush when refreshing forms
MHMighani Jun 2, 2022
77a63a2
Merge branch 'main' into client-version
MHMighani Jun 2, 2022
d55a7b1
Merge branch 'main' into client-version
MHMighani Jun 6, 2022
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
362 changes: 362 additions & 0 deletions client/package-lock.json

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions client/package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"homepage": "https://mhmighani.github.io/chortkeh",
"name": "chortkeh-client",
"version": "0.1.0",
"private": true,
Expand Down Expand Up @@ -35,6 +36,8 @@
"web-vitals": "^1.1.2"
},
"scripts": {
"predeploy": "npm run build",
"deploy": "gh-pages -d build",
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
Expand All @@ -57,5 +60,8 @@
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"gh-pages": "^4.0.0"
}
}
5 changes: 4 additions & 1 deletion client/src/App.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Redirect, Route, Switch } from "react-router-dom";
import { useEffect } from "react";
import { Route, Switch } from "react-router-dom";
import GoldCurrencyForm from "./components/forms/goldCurrencyForm";
import { ToastContainer } from "react-toastify";
import NavbarT from "./components/layout/navbar";
Expand All @@ -9,6 +9,7 @@ import AssetDetails from "./components/tables/assetsTable/assetDetails";
import PortfolioDetails from "./components/portfolio/portfolioDetails";
import Portfolio from "./components/portfolio/portfolio";
import Footer from "./components/layout/footer";
import OpeningModal from "./components/common/openingModal";
import { fetchAll } from "./actions";
import { useDispatch } from "react-redux";
import "react-toastify/dist/ReactToastify.css";
Expand All @@ -22,8 +23,10 @@ function App() {

return (
<div className="App">
<OpeningModal />
<NavbarT />
<Switch>
<Redirect from="/chortkeh" to="/" />
<Route exact path="/" component={Portfolio} />
<Route path="/portfolio-details" component={PortfolioDetails} />
<Route path="/assets/details/" component={AssetDetails} />
Expand Down
43 changes: 20 additions & 23 deletions client/src/actions/index.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,38 @@
import {
getAssets,
addAsset as addAssetApi,
editAsset as editAssetApi,
} from "../services/assetsServices";
import { getPrices } from "../services/pricesServices";
import { getHistoryRecord } from "../services/historyService";
import { deleteAssetBySubClass as deleteAssetBySubClassApi } from "../services/assetsServices";
import { deleteAsset } from "../services/assetsServices";

import data from "../data.json";
import * as actions from "./actionTypes";
import fakeHistoryBuilder from "../utils/fakeHistoryBuilder";
import getDateId from "../utils/getDateId";
import dateOperation from "../utils/dateOperation";
import { getTotalsByAssetClass } from "../utils";

const assets = [];

export const fetchAssets = () => async (dispatch) => {
const response = await getAssets();
dispatch({ type: actions.FETCH_ASSETS, payload: response.data });
dispatch({ type: actions.FETCH_ASSETS, payload: assets });
};

export const fetchPrices = () => async (dispatch) => {
const { data: goldCurrency } = await getPrices("goldcurrency");
const { data: stock } = await getPrices("stock");
const goldCurrency = data.goldcurrency || [];
const stock = (await data.stock) || [];

dispatch({
type: actions.FETCH_PRICES,
payload: { goldCurrency, stock },
});
};

export const fetchHistoryRecord = () => async (dispatch) => {
const { data: historyRecord } = await getHistoryRecord();
export const fetchHistoryRecord = () => async (dispatch, getState) => {
let totals = getTotalsByAssetClass(getState().assets);

totals["overall"] = totals["total"];
delete totals["total"];
totals = { ...totals, id: dateOperation(getDateId(), 1) };

const payload = totals.overall === 0 ? [] : fakeHistoryBuilder(60, totals);

dispatch({
type: actions.FETCH_HISTORY,
payload: historyRecord,
payload,
});
};

Expand All @@ -39,23 +41,18 @@ export const deleteAssetBySubClass = (toDeleteAsset) => async (dispatch) => {
type: actions.DELETE_ASSET_BY_SUBCLASS,
payload: toDeleteAsset,
});

await deleteAssetBySubClassApi(toDeleteAsset.assetSubClass);
};

export const deleteAssetById = (id) => async (dispatch) => {
dispatch({ type: actions.DELETE_ASSET_BY_ID, payload: id });
await deleteAsset(id);
};

export const addAsset = (asset) => async (dispatch) => {
dispatch({ type: actions.ADD_ASSET, payload: asset });
await addAssetApi(asset);
dispatch({ type: actions.ADD_ASSET, payload: { ...asset, id: Date.now() } });
};

export const editAsset = (assetId, newValue) => async (dispatch) => {
dispatch({ type: actions.EDIT_ASSET, payload: { assetId, newValue } });
await editAssetApi(assetId, newValue);
};

export const updateHistoryRecord = (newHistoryRecord) => async (dispatch) => {
Expand Down
29 changes: 29 additions & 0 deletions client/src/components/common/openingModal.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { useState } from "react";
import CustomModal from "./modal";

const OpeningModal = () => {
const [messageDisplay, setMessageDisplay] = useState(true);
const body = (
<ul>
<li>نسخه‌ای که در حال مشاهده‌اش هستید، نسخه کلاینت پروژه است</li>
<li>
اعداد در قسمت تاریخچه ارزش با ارزش منابع در تاریخ مربوطه هماهنگ نیستند و
برای نمایش دمو به صورت رندوم با اضافه کردن به پورتفولیو ساخته می‌شوند
</li>
<li>
قیمت‌ها‌ی درج شده در فرم‌ها به روز نیستند و از فایل data.json خوانده
می‌شوند
</li>
</ul>
);
return (
<CustomModal
show={messageDisplay}
handleClose={() => setMessageDisplay(false)}
title={"توجه"}
body={body}
/>
);
};

export default OpeningModal;
6 changes: 3 additions & 3 deletions client/src/components/portfolio/portfolioHistory.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,20 @@ const PortfolioHistory = ({ mappedAssets }) => {

let newData = [...historyRecord];
const normalizedOverall = getNormalizedOverallValue(mappedAssets);
let isNewRecord = true;
// let isNewRecord = true;

// checks if there is change in history
if (JSON.stringify(sortedData[0]) === JSON.stringify(normalizedOverall))
return;

// today's history was recorded before
if (sortedData[0]?.id === normalizedOverall.id) {
isNewRecord = false;
// isNewRecord = false;
newData[newData.length - 1] = { ...normalizedOverall };
} else {
newData = [...newData, normalizedOverall];
}
saveOverallHistory(normalizedOverall, isNewRecord);
// saveOverallHistory(normalizedOverall, isNewRecord);
dispatch(updateHistoryRecord(newData));
}, [mappedAssets, historyRecord, dispatch, sortedData]);

Expand Down
Loading