Skip to content

Commit

Permalink
Merge pull request #610 from idurar/feat/add-translate-hooks
Browse files Browse the repository at this point in the history
🇩🇿 🇨🇳 🇺🇸  🇫🇷 translation for IDURAR ERP CRM 3.0.beta 🎉
  • Loading branch information
salahlalami authored Oct 29, 2023
2 parents a9933c4 + ebc2e95 commit a44ec0b
Show file tree
Hide file tree
Showing 103 changed files with 2,120 additions and 1,535 deletions.
3 changes: 3 additions & 0 deletions frontend/.vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,8 @@
},
"[jsonc]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[markdown]": {
"editor.quickSuggestions": true
}
}
49 changes: 42 additions & 7 deletions frontend/src/app/HeaderContent/index.jsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import React from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { Link } from 'react-router-dom';
import { Avatar, Dropdown } from 'antd';
import { Avatar, Dropdown, Select } from 'antd';

import { languages } from '@/utils';

// import Notifications from '@/components/Notification';

import { AppstoreOutlined, SettingOutlined, LogoutOutlined } from '@ant-design/icons';
import photo from '@/style/images/photo.png';

import { selectLangCode } from '@/redux/translate/selectors';
import { checkImage } from '@/request';

import { selectCurrentAdmin } from '@/redux/auth/selectors';
import { langAction } from '@/redux/lang/actions';
import { translateAction } from '@/redux/translate/actions';
import history from '@/utils/history';

import { BASE_URL } from '@/config/serverApiConfig';
Expand All @@ -18,13 +22,14 @@ import useLanguage from '@/lang/useLanguage';

export default function HeaderContent() {
const currentAdmin = useSelector(selectCurrentAdmin);
const dispatch = useDispatch();

const dispatch = useDispatch();
const langCode = useSelector(selectLangCode);
const translate = useLanguage();

const srcImgProfile = checkImage(BASE_URL + currentAdmin?.photo)
? BASE_URL + currentAdmin?.photo
: photo;
: null;

const ProfileDropdown = () => {
return (
Expand Down Expand Up @@ -85,7 +90,7 @@ export default function HeaderContent() {
},
];
return (
<div className="headerIcon" style={{ position: 'absolute', right: 0, zIndex: '99' }}>
<div className="headerIcon" style={{ zIndex: '99' }}>
<Dropdown
menu={{
items,
Expand All @@ -108,9 +113,39 @@ export default function HeaderContent() {
<Avatar
icon={<AppstoreOutlined />}
onClick={() => {
dispatch(langAction.translate());
dispatch(translateAction.translate('zh_cn'));
}}
/>

<Select
showSearch
placeholder={translate('select language')}
defaultValue={langCode}
style={{ marginTop: '15px', width: '120px', float: 'right' }}
optionFilterProp="children"
filterOption={(input, option) => (option?.label ?? '').includes(input)}
filterSort={(optionA, optionB) =>
(optionA?.label ?? '').toLowerCase().startsWith((optionB?.label ?? '').toLowerCase())
}
onSelect={(value) => {
dispatch(translateAction.translate(value));
}}
>
{languages.map((language) => (
<Select.Option
key={language.value}
value={language.value}
label={language.label.toLowerCase()}
>
<div className="demo-option-label-item">
<span role="img" aria-label={language.label}>
{language.icon}
</span>
{language.label}
</div>
</Select.Option>
))}
</Select>
</div>
);
}
2 changes: 1 addition & 1 deletion frontend/src/app/Navigation/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ function Sidebar({ collapsible }) {
label: <Link to={'/admin'}>{translate('admin')}</Link>,
},
{
label: 'Settings',
label: translate('Settings'),
key: 'settings',
icon: <SettingOutlined />,
children: [
Expand Down
18 changes: 14 additions & 4 deletions frontend/src/app/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Router from '@/router';
import enUS from 'antd/es/locale/en_US';
import zhCN from 'antd/es/locale/zh_CN';
import frFR from 'antd/es/locale/fr_FR';
import arEG from 'antd/es/locale/ar_EG';

import useNetwork from '@/hooks/useNetwork';

Expand All @@ -12,7 +13,7 @@ import Navigation from '@/app/Navigation';

import { useSelector, useDispatch } from 'react-redux';
import { selectAuth } from '@/redux/auth/selectors';
import { selectLangCode } from '@/redux/lang/selectors';
import { selectLangCode } from '@/redux/translate/selectors';

import HeaderContent from '@/app/HeaderContent';
// import { useNetworkState } from "react-use";
Expand All @@ -35,11 +36,20 @@ function App() {
const langCode = useSelector(selectLangCode);

const [locale, setLocal] = useState(enUS);
const [direction, setDirection] = useState('ltr');

useEffect(() => {
if (langCode === 'fr_FR') {
if (langCode === 'fr_fr') {
setDirection('ltr');
setLocal(frFR);
} else if (langCode === 'zh_cn') {
setDirection('ltr');
setLocal(zhCN);
} else if (langCode === 'ar_eg') {
setDirection('rtl');
setLocal(arEG);
} else {
setDirection('ltr');
setLocal(enUS);
}

Expand All @@ -50,13 +60,13 @@ function App() {

if (!isLoggedIn)
return (
<ConfigProvider direction="ltr" locale={locale}>
<ConfigProvider direction={direction} locale={locale}>
<Router />
</ConfigProvider>
);
else {
return (
<ConfigProvider direction="ltr" locale={locale}>
<ConfigProvider direction={direction} locale={locale}>
<Layout style={{ minHeight: '100vh' }}>
<Navigation />
<Layout style={{ minHeight: '100vh' }}>
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/auth/auth.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ export const login = async ({ loginData }) => {
export const logout = async () => {
axios.defaults.withCredentials = true;
try {
window.localStorage.clear();
// window.localStorage.clear();
// window.localStorage.removeItem('isLoggedIn');
// window.localStorage.removeItem('auth');
await axios.post(API_BASE_URL + `logout?timestamp=${new Date().getTime()}`);
} catch (error) {
return errorHandler(error);
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/CrudModal/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default function DeleteModal({ config, children }) {
let {
entity,
entityDisplayLabels,
deleteMessage = translate('delete_message'),
deleteMessage = translate('are_you_sure_you_want_to_delete'),
modalTitle = translate('delete_confirmation'),
} = config;
const dispatch = useDispatch();
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/DataTable/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export default function DataTable({ config, extra = [] }) {
dataTableColumns = [
...dataTableColumns,
{
title: 'Action',
title: '',
key: 'action',
render: (_, record) => (
<Dropdown
Expand Down Expand Up @@ -161,7 +161,7 @@ export default function DataTable({ config, extra = [] }) {
ghost={false}
extra={[
<Button onClick={handelDataTableLoad} key={`${uniqueId()}`}>
Refresh
{translate('Refresh')}
</Button>,
<AddNewItem key={`${uniqueId()}`} config={config} />,
]}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/DeleteModal/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default function DeleteModal({ config }) {
let {
entity,
entityDisplayLabels,
deleteMessage = translate('delete_message'),
deleteMessage = translate('are_you_sure_you_want_to_delete'),
modalTitle = translate('delete_confirmation'),
} = config;
const dispatch = useDispatch();
Expand Down
27 changes: 27 additions & 0 deletions frontend/src/components/NotFound/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Result, Button } from 'antd';
import useLanguage from '@/lang/useLanguage';
import { useHistory } from 'react-router-dom';

export default function NotFound({ entity }) {
const translate = useLanguage();

const history = useHistory();

return (
<Result
status="404"
title={translate('error_404')}
subTitle={translate('Sorry the Page you requested does not exist')}
extra={
<Button
type="primary"
onClick={() => {
history.push(`/${entity?.toLowerCase()}`);
}}
>
{translate('Back')}
</Button>
}
/>
);
}
8 changes: 4 additions & 4 deletions frontend/src/components/ReadItem/index.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ const data = {
company: 'IDURAR',
managerSurname: 'Lalami ',
managerName: 'Salah Eddine',
email: 'idurardz@gmail.com',
phone: '05541 144 700',
email: 'test@gmail.com',
phone: '0777 777 777',
};

const readColumns = [
Expand All @@ -24,11 +24,11 @@ const readColumns = [
dataIndex: 'company',
},
{
title: 'Manager Surname',
title: 'Manager first name',
dataIndex: 'managerSurname',
},
{
title: 'Manager Name',
title: 'Manager last name',
dataIndex: 'managerName',
},
{
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/SelectAsync/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useState, useEffect, useRef } from 'react';
import { request } from '@/request';
import useFetch from '@/hooks/useFetch';
import { Select } from 'antd';
import { useHistory } from 'react-router-dom/cjs/react-router-dom.min';
import { useHistory } from 'react-router-dom';
import { PlusCircleOutlined } from '@ant-design/icons';

export default function SelectAsync({
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/components/Tag/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Tag } from 'antd';
import useLanguage from '@/lang/useLanguage';

export function StatusTag(status = 'draft') {
const translate = useLanguage();
let color =
status === 'draft'
? 'cyan'
Expand All @@ -12,5 +14,5 @@ export function StatusTag(status = 'draft') {
? 'orange'
: 'red';

return <Tag color={color}>{status && status.toUpperCase()}</Tag>;
return <Tag color={color}>{status && translate(status)}</Tag>;
}
4 changes: 2 additions & 2 deletions frontend/src/components/Visibility/index.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default function Visibility({ isVisible, children }) {
const show = isVisible ? { display: 'block', opacity: 1 } : { display: 'none', opacity: 0 };
export default function Visibility({ isOpen, children }) {
const show = isOpen ? { display: 'block', opacity: 1 } : { display: 'none', opacity: 0 };
return <div style={show}>{children}</div>;
}
8 changes: 4 additions & 4 deletions frontend/src/context/profileContext/types.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const OPEN_MODAL = 'OPEN_MODAL';
export const CLOSE_MODAL = 'CLOSE_MODAL';
export const OPEN_MODAL = 'OPEN_PASSWORD_MODAL';
export const CLOSE_MODAL = 'CLOSE_PASSWORD_MODAL';

export const OPEN_PANEL = 'OPEN_PANEL';
export const CLOSE_PANEL = 'CLOSE_PANEL';
export const OPEN_PANEL = 'OPEN_PROFILE_PANEL';
export const CLOSE_PANEL = 'CLOSE_PROFILE_PANEL';
85 changes: 0 additions & 85 deletions frontend/src/forms/KycForm.jsx

This file was deleted.

Loading

0 comments on commit a44ec0b

Please sign in to comment.