@qlover/create-app 0.4.4 → 0.4.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # @qlover/create-app
2
2
 
3
+ ## 0.4.5
4
+
5
+ ### Patch Changes
6
+
7
+ #### ✨ Features
8
+
9
+ - **create-app:** implement logout functionality and enhance localization ([c49f956](https://github.com/qlover/fe-base/commit/c49f956aecbc11a6b96b28309d112f7219a7dcca)) ([#438](https://github.com/qlover/fe-base/pull/438))
10
+
11
+ - Added a new LogoutButton component to handle user logout with a confirmation dialog.
12
+ - Introduced localization keys for logout dialog titles and content in both English and Chinese.
13
+ - Updated BaseHeader to conditionally display the logout button based on the layout context.
14
+ - Refactored AppConfig to utilize the Vite environment mode directly.
15
+ - Adjusted LoginInterface to accept a more generic parameter type for login.
16
+
17
+ This update improves user experience by providing a clear logout process and enhances localization support for logout-related messages.
18
+
3
19
  ## 0.4.4
4
20
 
5
21
  ### Patch Changes
package/dist/index.js CHANGED
@@ -2378,7 +2378,7 @@ var Generator = class {
2378
2378
 
2379
2379
  // package.json
2380
2380
  var package_default = {
2381
- version: "0.4.4",
2381
+ version: "0.4.5",
2382
2382
  description: "Create a new app with a single command"};
2383
2383
  function programArgs() {
2384
2384
  const program = new Command();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qlover/create-app",
3
- "version": "0.4.4",
3
+ "version": "0.4.5",
4
4
  "description": "Create a new app with a single command",
5
5
  "private": false,
6
6
  "type": "module",
@@ -0,0 +1,13 @@
1
+ /**
2
+ * @description logout dialog title
3
+ * @localZh 登出
4
+ * @localEn Logout
5
+ */
6
+ export const AUTH_LOGOUT_DIALOG_TITLE = 'Logout';
7
+
8
+ /**
9
+ * @description logout dialog content
10
+ * @localZh 确定要登出吗?
11
+ * @localEn Are you sure you want to logout?
12
+ */
13
+ export const AUTH_LOGOUT_DIALOG_CONTENT = 'Are you sure you want to logout?';
@@ -194,5 +194,7 @@
194
194
  "page.500.title": "500 - Server Error",
195
195
  "page.login.title": "Login",
196
196
  "page.register.title": "Register",
197
- "response.no.token": "Response not token value"
197
+ "response.no.token": "Response not token value",
198
+ "Logout": "Logout",
199
+ "Are you sure you want to logout?": "Are you sure you want to logout?"
198
200
  }
@@ -194,5 +194,7 @@
194
194
  "page.500.title": "500 - 服务器错误",
195
195
  "page.login.title": "登录",
196
196
  "page.register.title": "注册",
197
- "response.no.token": "响应内容没有 token 值"
197
+ "response.no.token": "响应内容没有 token 值",
198
+ "Logout": "登出",
199
+ "Are you sure you want to logout?": "确定要登出吗?"
198
200
  }
@@ -44,8 +44,10 @@ export class AppConfig implements EnvConfigInterface {
44
44
  * Current environment mode for Vite
45
45
  * @description Represents the running environment (development, production, etc.)
46
46
  * Automatically set based on the current .env file being used
47
+ *
48
+ * from vite.config `mode`
47
49
  */
48
- readonly env: string = '';
50
+ readonly env: string = import.meta.env.MODE;
49
51
 
50
52
  /**
51
53
  * Storage key for user authentication token
@@ -6,7 +6,7 @@ export interface RegisterFormData {
6
6
  agreeToTerms: boolean;
7
7
  }
8
8
  export interface LoginInterface {
9
- login(params: { username: string; password: string }): Promise<unknown>;
9
+ login(params: unknown): Promise<unknown>;
10
10
  logout(): void;
11
11
  register(params: RegisterFormData): Promise<unknown>;
12
12
  }
@@ -16,7 +16,8 @@ export const dialogHandler = new DialogHandler();
16
16
  */
17
17
  export const logger = new Logger({
18
18
  handlers: new ConsoleHandler(new ColorFormatter(loggerStyles)),
19
- silent: isProduction
19
+ silent: isProduction,
20
+ level: 'debug'
20
21
  });
21
22
 
22
23
  /**
@@ -15,7 +15,7 @@ export default function Layout() {
15
15
 
16
16
  return (
17
17
  <>
18
- <BaseHeader />
18
+ <BaseHeader showLogoutButton={false} />
19
19
  <div className="flex-1">
20
20
  <Outlet />
21
21
  </div>
@@ -9,7 +9,7 @@ export default function Layout() {
9
9
  data-testid="basic-layout"
10
10
  className="text-base min-h-screen bg-primary"
11
11
  >
12
- <BaseHeader />
12
+ <BaseHeader showLogoutButton />
13
13
 
14
14
  <div className="text-text bg-primary">
15
15
  <Outlet />
@@ -3,8 +3,13 @@ import LocaleLink from '@/uikit/components/LocaleLink';
3
3
  import LanguageSwitcher from '@/uikit/components/LanguageSwitcher';
4
4
  import { PublicAssetsPath } from '@/base/cases/PublicAssetsPath';
5
5
  import { IOC } from '@/core/IOC';
6
+ import LogoutButton from './LogoutButton';
6
7
 
7
- export default function BaseHeader() {
8
+ export default function BaseHeader({
9
+ showLogoutButton
10
+ }: {
11
+ showLogoutButton?: boolean;
12
+ }) {
8
13
  return (
9
14
  <header className="h-14 bg-secondary border-b border-border sticky top-0 z-50">
10
15
  <div className="flex items-center justify-between h-full px-4 mx-auto max-w-7xl">
@@ -26,6 +31,8 @@ export default function BaseHeader() {
26
31
  <div className="flex items-center gap-4">
27
32
  <LanguageSwitcher />
28
33
  <ThemeSwitcher />
34
+
35
+ {showLogoutButton && <LogoutButton />}
29
36
  </div>
30
37
  </div>
31
38
  </header>
@@ -0,0 +1,32 @@
1
+ import { UserService } from '@/base/services/UserService';
2
+ import { IOC } from '@/core/IOC';
3
+ import {
4
+ AUTH_LOGOUT_DIALOG_CONTENT,
5
+ AUTH_LOGOUT_DIALOG_TITLE
6
+ } from '@config/Identifier/Auth';
7
+ import { Button } from 'antd';
8
+ import { useCallback } from 'react';
9
+ import { useTranslation } from 'react-i18next';
10
+
11
+ export default function LogoutButton() {
12
+ const { t } = useTranslation();
13
+
14
+ const tTitle = t(AUTH_LOGOUT_DIALOG_TITLE);
15
+ const tContent = t(AUTH_LOGOUT_DIALOG_CONTENT);
16
+
17
+ const onClick = useCallback(() => {
18
+ IOC('DialogHandler').confirm({
19
+ title: tTitle,
20
+ content: tContent,
21
+ onOk: () => {
22
+ IOC(UserService).logout();
23
+ }
24
+ });
25
+ }, [tTitle, tContent]);
26
+
27
+ return (
28
+ <Button danger onClick={onClick}>
29
+ {tTitle}
30
+ </Button>
31
+ );
32
+ }
@@ -118,7 +118,6 @@ export default defineConfig({
118
118
  server: {
119
119
  port: Number(process.env.VITE_SERVER_PORT || 3200)
120
120
  },
121
- mode: process.env.NODE_ENV,
122
121
  test: {
123
122
  environment: 'jsdom',
124
123
  globals: true,