Ai trái ngành muốn chuyển sang IT hãy nhìn những hình này

Giống liệt kê trường hợp ra nhỉ:
If cái này abcd. Ko đc thì
If efgh ....
Ijklficjdoekvoosldkkf

Thôi tui cận thị nhìn hồi nhức mắt nhức đầu vl aaaaaaaaaa
 
Hình 1 đoán là đang làm navbar dropdown,
Hình 2 setup môi trường.
Hình 3 gọi API để làm gì đấy.
Hình 4 funtion có chức năng lấy tọa độ và vẽ lên màn hình.

:rolleyes:.

đấy là bình thường chứ nhìn code cũ của cty tôi đây, 1 đoạn thần chú mà đéo ai biết nó làm cái gì luôn. Tự tin public vì éo sợ ai đọc và hiểu đc :after_boom:

JavaScript:
    async getUser() {
        const { dispatch } = this.props;
        const user = await dispatch(getCookie("user"));
        //console.log(user.user);
        if (typeof user !== "undefined") {
            this.setState({ user: JSON.parse(user) });
            //console.log(this.state.user.user.email)
            //console.log(this.state.user.token);
            let token = "Bearer " + this.state.user.token;
            let params = {
                email: this.state.user.user.email,
            };
            await callApi("POST", GETAVATARUSER, params, token).then((res) => {
                this.setState({
                    avatar: res.data.data ? URLSERVERIMAGE + res.data.data : "",
                });
            });
            // console.log(this.state.user.user.userType === Constant.FACTORY);
            if (
                this.state.user.user.userType === Constant.SUPERADMIN ||
                this.state.user.user.userType === Constant.GOVERMENT
            ) {
                this.setState({
                    isShowMenu: [
                        true,
                        true,
                        true,
                        true,
                        true,
                        true,
                        true,
                        true,
                        true,
                        true,
                        true,
                        false,
                        true,
                        true,
                        true,
                        true,
                    ],
                    isShowDriver: true,
                    isShowGoogleMap: true,
                    isShowThanhtra: true,
                    isShowCalender: true,
                    isShowUpdateOrder: true,
                    isShowShippingManager: true,
                    isShowRentalPartner: true,
                    isShowDistributionAgency: true,
                    isShowIndustry: true,
                    isShowRestaurant: true,
                    isShowCar: true,
                    isOrder: true,
                    isShowKinhDoanh: true,
                });
            } else if (
                this.state.user.user.userType === Constant.FACTORY &&
                this.state.user.user.userRole !== "Deliver" &&
                this.state.user.user.userRole !== "Inspector"
            ) {
                if (this.state.user.user.userRole === "SuperAdmin") {
                    this.setState({
                        isShowMenu: [
                            true,
                            false,
                            false,
                            true,
                            true,
                            false,
                            true,
                            true,
                            false,
                            true,
                            false,
                            false,
                            true,
                            true,
                        ],
                        isShowDriver: true,
                        isShowGoogleMap: true,
                        isShowThanhtra: true,
                        isShowCalender: true,
                        isShowCreateOrder: true,
                        isShowRentalPartner: true,
                        isShowDistributionAgency: true,
                        isShowIndustry: true,
                        isShowRestaurant: true,
                        isShowCar: true,
                        isOrder: true,
                        isShowKinhDoanh: true,
                        isShowTurnBack: true,
                    });
                } else {
                    this.setState({
                        isShowMenu: [
                            true,
                            false,
                            false,
                            true,
                            true,
                            false,
                            true,
                            true,
                            false,
                            false,
                            false,
                            false,
                            false,
                            false,
                        ],

                        // isShowMenu: [true, false, false, true, true, true, true, true, false, true, false, false, true, false],
                        isShowDriver: true,
                        isShowGoogleMap: true,
                        isShowThanhtra: false,
                        isShowCalender: false,
                        isShowCreateOrder: false,
                        isShowUpdateOrder: true,
                        isShowShippingManager: true,
                        isShowRentalPartner: false,
                        isShowCar: true,
                        isOrder: false,
                        isShowKinhDoanh: false,
                    });
                }
            } else if (
                this.state.user.user.userType === Constant.STATION &&
                this.state.user.user.userRole !== "Deliver" &&
                this.state.user.user.userRole !== "Inspector"
            ) {
                this.setState({
                    isShowMenu: [
                        true,
                        false,
                        false,
                        false,
                        false,
                        false,
                        true,
                        false,
                        false,
                        false,
                    ],
                    isShowDriver: true,
                    isShowGoogleMap: true,
                    isShowThanhtra: false,
                    isShowCalender: true,
                    isShowCreateOrder: false,
                    isShowUpdateOrder: true,
                    isShowShippingManager: true,
                    isShowRentalPartner: false,
                    isShowDistributionAgency: false,
                    isShowIndustry: false,
                    isShowRestaurant: false,
                    isShowCar: false,
                    isOrder: false,
                    isShowKinhDoanh: true,
                });
            } else if (
                this.state.user.user.userType === Constant.GENERAL &&
                this.state.user.user.userRole !== "Deliver" &&
                this.state.user.user.userRole !== "Inspector"
            ) {
                this.setState({
                    isShowMenu: [
                        true,
                        false,
                        false,
                        false,
                        false,
                        true,
                        true,
                        false,
                        false,
                        false,
                    ],
                    isShowDriver: true,
                    isShowGoogleMap: false,
                    isShowThanhtra: false,
                    isShowCalender: false,
                    isShowCreateOrder: false,
                    isShowUpdateOrder: true,
                    isShowShippingManager: true,
                    isShowRentalPartner: false,
                    isShowDistributionAgency: false,
                    isShowIndustry: false,
                    isShowRestaurant: false,
                    isShowCar: false,
                    isOrder: false,
                    isShowKinhDoanh: true,
                });
            } else if (
                this.state.user.user.userType === Constant.FIXER &&
                this.state.user.user.userRole !== "Deliver" &&
                this.state.user.user.userRole !== "Inspector"
            ) {
                this.setState({
                    isShowMenu: [
                        false,
                        false,
                        false,
                        false,
                        false,
                        false,
                        true,
                        false,
                        false,
                        false,
                    ],
                    isShowDriver: true,
                    isShowGoogleMap: false,
                    isShowThanhtra: false,
                    isShowCalender: false,
                    isShowCreateOrder: false,
                    isShowUpdateOrder: true,
                    isShowShippingManager: true,
                    isShowRentalPartner: false,
                    isShowDistributionAgency: false,
                    isShowIndustry: false,
                    isShowRestaurant: false,
                    isShowCar: false,
                    isOrder: false,
                    isShowKinhDoanh: false,
                });
            } else if (
                this.state.user.user.userType === Constant.AGENCY &&
                this.state.user.user.userRole !== "Deliver" &&
                this.state.user.user.userRole !== "Inspector"
            ) {
                if (this.state.user.user.parentRoot === "")
                    this.setState({
                        isShowMenu: [
                            true,
                            false,
                            false,
                            false,
                            false,
                            false,
                            true,
                            false,
                            true,
                            true,
                            true,
                        ],
                        isShowDriver: true,
                        isShowGoogleMap: false,
                        isShowThanhtra: false,
                        isShowCalender: false,
                        isShowCreateOrder: false,
                        isShowUpdateOrder: false,
                        isShowShippingManager: false,
                        isShowRentalPartner: false,
                        isShowDistributionAgency: false,
                        isShowIndustry: false,
                        isShowRestaurant: false,
                        isShowCar: false,
                        isOrder: false,
                        isShowKinhDoanh: true,
                    });
                else
                    this.setState({
                        isShowMenu: [
                            true,
                            false,
                            false,
                            false,
                            false,
                            false,
                            true,
                            false,
                            false,
                            false,
                            false,
                        ],
                        isShowDriver: true,
                        isShowGoogleMap: false,
                        isShowThanhtra: false,
                        isShowCalender: false,
                        isShowCreateOrder: false,
                        isShowUpdateOrder: false,
                        isShowShippingManager: true,
                        isShowRentalPartner: false,
                        isShowDistributionAgency: false,
                        isShowIndustry: false,
                        isShowRestaurant: false,
                        isShowCar: false,
                        isOrder: false,
                        isShowKinhDoanh: false,
                    });
            } else if (
                this.state.user.user.userType === Constant.NORMAL &&
                this.state.user.user.userRole !== "Deliver" &&
                this.state.user.user.userRole !== "Inspector"
            ) {
                this.setState({
                    isShowMenu: [
                        true,
                        true,
                        true,
                        true,
                        true,
                        true,
                        true,
                        true,
                        true,
                        false,
                    ],
                    isShowDriver: true,
                    isShowGoogleMap: true,
                    isShowThanhtra: false,
                    isShowCalender: false,
                    isShowCreateOrder: false,
                    isShowUpdateOrder: true,
                    isShowShippingManager: true,
                    isShowRentalPartner: false,
                    isShowDistributionAgency: false,
                    isShowIndustry: false,
                    isShowRestaurant: false,
                    isShowCar: false,
                    isOrder: false,
                });
            } else if (
                this.state.user.user.userRole === "Deliver" ||
                this.state.user.user.userRole === "Inspector"
            ) {
                this.setState({
                    isShowMenu: [
                        false,
                        false,
                        false,
                        false,
                        false,
                        false,
                        false,
                        false,
                        false,
                        false,
                        false,
                        false,
                        false,
                        false,
                    ],
                    isShowDriver: false,
                    isShowGoogleMap: false,
                    isShowThanhtra: false,
                    isShowCalender: false,
                    isShowCreateOrder: false,
                    isShowUpdateOrder: false,
                    isShowShippingManager: false,
                    isShowRentalPartner: false,
                    isShowDistributionAgency: false,
                    isShowIndustry: false,
                    isShowRestaurant: false,
                    isShowCar: false,
                    isOrder: false,
                });
            }
        }
    }
này chắc react, thím code bựa kinh vậy :sexy_girl:
 
parentIs :confused:

mấy dòng code này doạ được ai à thớt
chưa kể cái kiểu convention hình 1 nhìn bừa bộn, nhìn ghét thật :rolleyes:

nên kiếm ví dụ khác chuẩn hơn
 
này chắc react, thím code bựa kinh vậy :sexy_girl:
không phải tôi, của tiền nhân để lại. Tôi biết cái đó là để phân loại user và chặn người dùng ko đc vào trong các page không thuộc quyền. Hỡi ôi, trên đời dưới thế có ai làm vậy bao giờ. Sao ko lưu dạng Object từng menu trong đó có key role để lấy data từ sever về check là đc.

Mà buồn cười ở chỗ mặc dù phân quyền ko cho nhấn vào menu nhưng vẫn dùng thanh địa chỉ để acess vào đc. :(

Hên dự án khách hàng xài kín, chứ public ra thì chắc ko dám ghi vào CV. Em xin lỗi sếp vì lúc đấy em trình còi ko refactor lại cho sếp đc =((
 
không phải tôi, của tiền nhân để lại. Tôi biết cái đó là để phân loại user và chặn người dùng ko đc vào trong các page không thuộc quyền. Hỡi ôi, trên đời dưới thế có ai làm vậy bao giờ. Sao ko lưu dạng Object từng menu trong đó có key role để lấy data từ sever về check là đc.

Mà buồn cười ở chỗ mặc dù phân quyền ko cho nhấn vào menu nhưng vẫn dùng thanh địa chỉ để acess vào đc. :(

Hên dự án khách hàng xài kín, chứ public ra thì chắc ko dám ghi vào CV. Em xin lỗi sếp vì lúc đấy em trình còi ko refactor lại cho sếp đc =((
nếu là phân quyền thì nên giao cho Backend thì hơn :big_smile:
 
nếu là phân quyền thì nên giao cho Backend thì hơn :big_smile:

Backend trả về role và sẽ check lại khi gọi API get hoặc push dữ liệu. Còn bọn tôi làm là ko cho client vào đc page đó ở trên FE.

Tôi có đề xuất là làm lại, dùng ContextAPI mặc định của React rồi lưu data page ở chỗ đấy. xong cấp lại cho thằng Layout và các compoent con. Lúc login thì đối chiếu với bảng data page của api login trả về rồi từ đó render các component con.

Nhưng cả team say no nên thôi, có lần thêm 1 cái menu rồi phân quyền cho nó mất 2 ngày xong bị trầm cảm. Xong sau này sếp muốn có tính năng Điều Chỉnh Phân Quyền ở client thì lúc đấy tôi biết dự án đã đến hồi không thể cứu vãn đc nữa. =((
 
Backend trả về role và sẽ check lại khi gọi API get hoặc push dữ liệu. Còn bọn tôi làm là ko cho client vào đc page đó ở trên FE.

Tôi có đề xuất là làm lại, dùng ContextAPI mặc định của React rồi lưu data page ở chỗ đấy. xong cấp lại cho thằng Layout và các compoent con. Lúc login thì đối chiếu với bảng data page của api login trả về rồi từ đó render các component con.

Nhưng cả team say no nên thôi, có lần thêm 1 cái menu rồi phân quyền cho nó mất 2 ngày xong bị trầm cảm. Xong sau này sếp muốn có tính năng Điều Chỉnh Phân Quyền ở client thì lúc đấy tôi biết dự án đã đến hồi không thể cứu vãn đc nữa. =((
cực vãi, mà context thấy ko tốt lắm, quá rối cho code component, thím nên làm redux thì thử redux toolkit ấy, đang trend:sexy_girl:
 
cực vãi, mà context thấy ko tốt lắm, quá rối cho code component, thím nên làm redux thì thử redux toolkit ấy, đang trend:sexy_girl:
Dự án đó có dùng redux đâu, khổ thế mới lại. Đã vậy lib thì toàn mấy cái cũ mèm ko đc sp nữa. :after_boom:
 
Backend trả về role và sẽ check lại khi gọi API get hoặc push dữ liệu. Còn bọn tôi làm là ko cho client vào đc page đó ở trên FE.

Tôi có đề xuất là làm lại, dùng ContextAPI mặc định của React rồi lưu data page ở chỗ đấy. xong cấp lại cho thằng Layout và các compoent con. Lúc login thì đối chiếu với bảng data page của api login trả về rồi từ đó render các component con.

Nhưng cả team say no nên thôi, có lần thêm 1 cái menu rồi phân quyền cho nó mất 2 ngày xong bị trầm cảm. Xong sau này sếp muốn có tính năng Điều Chỉnh Phân Quyền ở client thì lúc đấy tôi biết dự án đã đến hồi không thể cứu vãn đc nữa. =((


Nhìn code if else tùm lum hầm bà lằng là muốn quăng vô sọt rác. Code vậy mà vẫn được merge vô master

Code không phải để cho chạy được là xong, code phải nghĩ tới maintainability + extend sau này nữa. Tất nhiên không cần phải nghĩ quá sâu xa, nhưng cái đống if-else ở trên thì gớm quá sức tưởng tượng

via theNEXTvoz for iPhone
 
Nhìn code if else tùm lum hầm bà lằng là muốn quăng vô sọt rác. Code vậy mà vẫn được merge vô master

Code không phải để cho chạy được là xong, code phải nghĩ tới maintainability + extend sau này nữa. Tất nhiên không cần phải nghĩ quá sâu xa, nhưng cái đống if-else ở trên thì gớm quá sức tưởng tượng

via theNEXTvoz for iPhone
gặp mình là mình tạo cái util, bê sạch đám logic qua hết cho clean
 
Vozlit trẻ trâu muốn chứng tỏ cái gì ở đây :doubt: Thằng đéo nào muốn học code chẳng biết trước sẽ phải làm mấy cái này
 
Back
Top