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

Refactor Home Page #11

Merged
merged 30 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
931500a
refactor(component): divide sub folder in src/components and remove j…
ngyngcphu Sep 23, 2023
5c21b1d
chore(server): create a mock-server to fake API
ngyngcphu Sep 23, 2023
9124008
refactor(flow): create flow-call API from types, services, states
ngyngcphu Sep 23, 2023
a50e800
feat(navigation_bar): edit AppNavigation, AppDrawer and ToglleSidebarBtn
Minhtuei Sep 23, 2023
a6357a6
refactor(HomePage): limit the use of HTML in React
ngyngcphu Sep 23, 2023
b034d0f
feat(add_ux_sidebar): add ux for sidebar&navbar, resolve merge confli…
Minhtuei Sep 26, 2023
e1e67ed
refactor(side-nav-bar): implement navigation logic and add closure hook
ngyngcphu Sep 30, 2023
c598c69
Merge pull request #10 from TickLabVN/sub-feature/navigation
ngyngcphu Sep 30, 2023
c9e391b
feat(template): create choose-file-box and upload-document-box template
ngyngcphu Sep 30, 2023
96b899a
fix(form-ux): create smoothness between nested dialogs
ngyngcphu Oct 1, 2023
a4f6dab
refactor(folder structure): add folder order in component
ngyngcphu Oct 1, 2023
96f29ee
feat(order): create workflows template for order printing
ngyngcphu Oct 1, 2023
8904e71
fix(naming): rename Form, Box in component/order
ngyngcphu Oct 1, 2023
29a7c41
feat(order): create templates for 2 form: wallet and order-success
ngyngcphu Oct 1, 2023
44ce0b0
chore(comment): rename owner's task
ngyngcphu Oct 1, 2023
26ac74d
Merge pull request #12 from TickLabVN/sub-feature/top-up-wallet
ngyngcphu Oct 1, 2023
ab5a0c8
feat(ChooseFileBox): release Upload file component
MLAkainu Oct 1, 2023
6990ec0
test(preview): create TestPreviewPage to test preview document
ngyngcphu Oct 1, 2023
b30bfc9
fix(ChooseFileBox): fix choose file component
MLAkainu Oct 2, 2023
0fe7b8a
fix(choosefilebox): fix some lg desktop but I don't fix width Dialogb…
MLAkainu Oct 2, 2023
8b1c4d4
chore(mock-server): fake file-server to upload file
ngyngcphu Oct 7, 2023
2ce2073
feat: implement TestPreviewPage, remove Auth to test on mock-server
qmi03 Oct 8, 2023
34754ba
fix(mobile_box): fix choose file mobile
MLAkainu Oct 9, 2023
acdd30e
fix(format_tailwind): fix width heigth format
MLAkainu Oct 9, 2023
d739480
feat(file): preview image after uploading
ngyngcphu Oct 12, 2023
c763152
Merge branch 'sub-feature/preview-document' of github.com:TickLabVN/s…
ngyngcphu Oct 12, 2023
a4f45c5
test(file): preview pdf file after uploading
ngyngcphu Oct 12, 2023
23c5877
test(file): fix unknown prop in styled-component and valid prop in is…
ngyngcphu Oct 12, 2023
c914762
feat(file): complete uploading and previewing file
ngyngcphu Oct 12, 2023
ca2fa16
Merge pull request #14 from TickLabVN/sub-feature/choose-file-to-print
ngyngcphu Oct 12, 2023
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
11 changes: 8 additions & 3 deletions .barrelsby.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
{
"directory": [
"./src/components",
"./src/components/common",
"./src/components/home",
"./src/components/order",
"./src/constants",
"./src/hooks",
"./src/interfaces",
"./src/layouts",
"./src/pages",
"./src/services",
"./src/states",
"./src/services/common",
"./src/services/home",
"./src/states/common",
"./src/states/home",
"./src/states/order",
"./src/utils"
],
"delete": true
Expand Down
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# This file is not allowed to be deleted, because it represents which environment variables to use when the project is open-source.
VITE_BACKEND_URL=
33 changes: 27 additions & 6 deletions db.json → __mock-server__/db.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"orders": [
{
"id": "1233-defc",
"status": "Progressing",
"status": "progressing",
"location": "Thu Duc, Ho Chi Minh, Viet Nam",
"number": 2,
"fileName": "file1.pdf",
Expand All @@ -12,7 +12,7 @@
},
{
"id": "1245-afce",
"status": "Ready",
"status": "ready",
"location": "Tan Phu, Ho Chi Minh, Viet Nam",
"number": 2,
"fileName": "file2.docx",
Expand All @@ -22,7 +22,7 @@
},
{
"id": "1267-rfce",
"status": "Done",
"status": "done",
"location": "Tan Phu, Ho Chi Minh, Viet Nam",
"number": 2,
"fileName": "file3.txt",
Expand All @@ -32,7 +32,7 @@
},
{
"id": "1267-rfce",
"status": "Canceled",
"status": "canceled",
"location": "Tan Phu, Ho Chi Minh, Viet Nam",
"number": 2,
"fileName": "file3.txt",
Expand All @@ -42,13 +42,34 @@
},
{
"id": "1267-rfce",
"status": "Done",
"status": "done",
"location": "Tan Phu, Ho Chi Minh, Viet Nam",
"number": 2,
"fileName": "file3.txt",
"pageNumber": 5,
"coins": 30,
"paid": "Paid"
}
]
],
"slides": [
{
"src": "https://e-learning.hcmut.edu.vn/theme/boost/images/slbktv.jpg?1695219022292",
"alt": "slide1"
},
{
"src": "https://e-learning.hcmut.edu.vn/theme/boost/images/slbk.jpg?1695219022805",
"alt": "slide2"
},
{
"src": "https://static.tuoitre.vn/tto/i/s626/2016/04/05/dai-hoc-bach-khoa-tp-hcm-cong-bo-phuong-an-tuyen-sinh-2015jpg-1459820200.jpg",
"alt": "slide3"
},
{
"src": "https://we25.vn/media2018/Img_News/2020/06/08/khuon-vien-dh-bach-khoa-tp-hcm-khien-dan-tinh-me-man-voi-nhung-hanh-cay-xanh-tham-toa-bong-mat-quanh-nam-14_20200608150159.jpg",
"alt": "slide4"
}
],
"user": {
"coins": 200
}
}
107 changes: 107 additions & 0 deletions __mock-server__/file-server/file.controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
const uploadFile = require('./upload.middleware');
const fs = require('fs');
const baseUrl = 'http://localhost:3003/files/';

const upload = async (req, res) => {
try {
await uploadFile(req, res);

if (req.file === undefined) {
return res.status(400).send({ message: 'Please upload a file!' });
}

res.status(200).send({
message: 'Uploaded the file successfully: ' + req.file.originalname
});
} catch (err) {
console.log(err);

if (err.code === 'LIMIT_FILE_SIZE') {
return res.status(500).send({
message: 'File size cannot be larger than 2MB!'
});
}

res.status(500).send({
message: `Could not upload the file: ${req.file.originalname}. ${err}`
});
}
};

const getListFiles = (req, res) => {
const directoryPath = __basedir + '/resources/';

fs.readdir(directoryPath, function (err, files) {
if (err) {
res.status(500).send({
message: 'Unable to scan files!'
});
}

let fileInfos = [];

files.forEach((file) => {
fileInfos.push({
name: file,
url: baseUrl + file
});
});

res.status(200).send(fileInfos);
});
};

const download = (req, res) => {
const fileName = req.params.name;
const directoryPath = __basedir + '/resources/';

res.download(directoryPath + fileName, fileName, (err) => {
if (err) {
res.status(500).send({
message: 'Could not download the file. ' + err
});
}
});
};

const remove = (req, res) => {
const fileName = req.params.name;
const directoryPath = __basedir + '/resources/';

fs.unlink(directoryPath + fileName, (err) => {
if (err) {
res.status(500).send({
message: 'Could not delete the file. ' + err
});
}

res.status(200).send({
message: 'File is deleted.'
});
});
};

const removeSync = (req, res) => {
const fileName = req.params.name;
const directoryPath = __basedir + '/resources/';

try {
fs.unlinkSync(directoryPath + fileName);

res.status(200).send({
message: 'File is deleted.'
});
} catch (err) {
res.status(500).send({
message: 'Could not delete the file. ' + err
});
}
};

module.exports = {
upload,
getListFiles,
download,
remove,
removeSync
};
14 changes: 14 additions & 0 deletions __mock-server__/file-server/file.route.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const express = require('express');
const router = express.Router();
const controller = require('./file.controller');

let routes = (app) => {
router.post('/upload', controller.upload);
router.get('/files', controller.getListFiles);
router.get('/files/:name', controller.download);
router.delete('/files/:name', controller.remove);

app.use(router);
};

module.exports = routes;
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions __mock-server__/file-server/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const cors = require('cors');
const express = require('express');
const app = express();

global.__basedir = __dirname;

var corsOptions = {
origin: 'http://localhost:3000',
credentials: true
};

app.use(cors(corsOptions));

const initRoutes = require('./file.route');

app.use(express.urlencoded({ extended: true }));
initRoutes(app);

let port = 3003;
app.listen(port, () => {
console.log(`Running at localhost:${port}`);
});
21 changes: 21 additions & 0 deletions __mock-server__/file-server/upload.middleware.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const util = require('util');
const multer = require('multer');
const maxSize = 2 * 1024 * 1024;

let storage = multer.diskStorage({
destination: (req, file, cb) => {
cb(null, __basedir + '/resources/');
},
filename: (req, file, cb) => {
console.log(file.originalname);
cb(null, file.originalname);
}
});

let uploadFile = multer({
storage: storage,
limits: { fileSize: maxSize }
}).single('file');

let uploadFileMiddleware = util.promisify(uploadFile);
module.exports = uploadFileMiddleware;
16 changes: 16 additions & 0 deletions __mock-server__/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "mock-server",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"dependencies": {
"cors": "^2.8.5",
"express": "^4.18.2",
"json-server": "^0.17.3",
"multer": "^1.4.5-lts.1"
},
"scripts": {
"start": "node server.js",
"start:file-server": "node ./file-server/server.js"
}
}
10 changes: 10 additions & 0 deletions __mock-server__/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const jsonServer = require('json-server');
const server = jsonServer.create();
const router = jsonServer.router('db.json');
const middlewares = jsonServer.defaults();
const port = process.env.PORT || 3002;

server.use(middlewares);
server.use(router);

server.listen(port);
Loading