@invoice-sdk/widget 0.0.0

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/README.md ADDED
@@ -0,0 +1,54 @@
1
+ # React + TypeScript + Vite
2
+
3
+ This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
4
+
5
+ Currently, two official plugins are available:
6
+
7
+ - [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react) uses [Babel](https://babeljs.io/) for Fast Refresh
8
+ - [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
9
+
10
+ ## Expanding the ESLint configuration
11
+
12
+ If you are developing a production application, we recommend updating the configuration to enable type-aware lint rules:
13
+
14
+ ```js
15
+ export default tseslint.config({
16
+ extends: [
17
+ // Remove ...tseslint.configs.recommended and replace with this
18
+ ...tseslint.configs.recommendedTypeChecked,
19
+ // Alternatively, use this for stricter rules
20
+ ...tseslint.configs.strictTypeChecked,
21
+ // Optionally, add this for stylistic rules
22
+ ...tseslint.configs.stylisticTypeChecked,
23
+ ],
24
+ languageOptions: {
25
+ // other options...
26
+ parserOptions: {
27
+ project: ['./tsconfig.node.json', './tsconfig.app.json'],
28
+ tsconfigRootDir: import.meta.dirname,
29
+ },
30
+ },
31
+ })
32
+ ```
33
+
34
+ You can also install [eslint-plugin-react-x](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-x) and [eslint-plugin-react-dom](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-dom) for React-specific lint rules:
35
+
36
+ ```js
37
+ // eslint.config.js
38
+ import reactX from 'eslint-plugin-react-x'
39
+ import reactDom from 'eslint-plugin-react-dom'
40
+
41
+ export default tseslint.config({
42
+ plugins: {
43
+ // Add the react-x and react-dom plugins
44
+ 'react-x': reactX,
45
+ 'react-dom': reactDom,
46
+ },
47
+ rules: {
48
+ // other rules...
49
+ // Enable its recommended typescript rules
50
+ ...reactX.configs['recommended-typescript'].rules,
51
+ ...reactDom.configs.recommended.rules,
52
+ },
53
+ })
54
+ ```
@@ -0,0 +1,28 @@
1
+ import js from '@eslint/js'
2
+ import globals from 'globals'
3
+ import reactHooks from 'eslint-plugin-react-hooks'
4
+ import reactRefresh from 'eslint-plugin-react-refresh'
5
+ import tseslint from 'typescript-eslint'
6
+
7
+ export default tseslint.config(
8
+ { ignores: ['dist'] },
9
+ {
10
+ extends: [js.configs.recommended, ...tseslint.configs.recommended],
11
+ files: ['**/*.{ts,tsx}'],
12
+ languageOptions: {
13
+ ecmaVersion: 2020,
14
+ globals: globals.browser,
15
+ },
16
+ plugins: {
17
+ 'react-hooks': reactHooks,
18
+ 'react-refresh': reactRefresh,
19
+ },
20
+ rules: {
21
+ ...reactHooks.configs.recommended.rules,
22
+ 'react-refresh/only-export-components': [
23
+ 'warn',
24
+ { allowConstantExport: true },
25
+ ],
26
+ },
27
+ },
28
+ )
package/index.html ADDED
@@ -0,0 +1,13 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <link rel="icon" type="image/svg+xml" href="/vite.svg" />
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
+ <title>Vite + React + TS</title>
8
+ </head>
9
+ <body>
10
+ <div id="root"></div>
11
+ <script type="module" src="/src/main.tsx"></script>
12
+ </body>
13
+ </html>
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "dependencies": {
3
+ "@invoice-sdk/api": "workspace:*",
4
+ "react-hook-form": "^7.56.4",
5
+ "react-router-dom": "6.30.1",
6
+ "zod": "^3.25.42",
7
+ "zustand": "^5.0.5"
8
+ },
9
+ "devDependencies": {
10
+ "@eslint/js": "^9.25.0",
11
+ "@hookform/resolvers": "^5.0.1",
12
+ "@tailwindcss/vite": "^4.1.8",
13
+ "@types/react": "^19.1.2",
14
+ "@types/react-dom": "^19.1.2",
15
+ "@vitejs/plugin-react": "^4.4.1",
16
+ "autoprefixer": "^10.4.21",
17
+ "eslint": "^9.25.0",
18
+ "eslint-plugin-react-hooks": "^5.2.0",
19
+ "eslint-plugin-react-refresh": "^0.4.19",
20
+ "globals": "^16.0.0",
21
+ "tailwindcss": "^4.1.8",
22
+ "typescript": "~5.8.3",
23
+ "typescript-eslint": "^8.30.1",
24
+ "vite": "^6.3.5",
25
+ "vite-tsconfig-paths": "^5.1.4"
26
+ },
27
+ "name": "@invoice-sdk/widget",
28
+ "peerDependencies": {
29
+ "react": "^19.1.0",
30
+ "react-dom": "^19.1.0"
31
+ },
32
+ "publishConfig": {
33
+ "access": "public"
34
+ },
35
+ "scripts": {
36
+ "build": "tsc -b && vite build",
37
+ "dev": "vite",
38
+ "lint": "eslint .",
39
+ "preview": "vite preview"
40
+ },
41
+ "type": "module",
42
+ "version": "0.0.0"
43
+ }
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>
package/src/App.css ADDED
@@ -0,0 +1 @@
1
+ @import "tailwindcss";
package/src/App.tsx ADDED
@@ -0,0 +1,40 @@
1
+ import { BrowserRouter, Navigate, Route, Routes } from 'react-router-dom';
2
+ import './App.css';
3
+ import Layout from './components/layout';
4
+ import RegistrationForm from './pages/register';
5
+ import SelectPlan from './pages/select-plan';
6
+ import SelectProvider from './pages/select-provider';
7
+ import Status from './pages/status';
8
+
9
+ function InvoiceRegisterWidget() {
10
+
11
+ return (
12
+ <BrowserRouter>
13
+ <Routes>
14
+ {/* ANY route under "/" will first render <Layout /> */}
15
+ <Route element={<Layout />}>
16
+ {/* Default redirect (if you want “/” → “/home” for example) */}
17
+ <Route index element={<Navigate to="/select-provider" replace />} />
18
+
19
+ {/* Actual pages */}
20
+ <Route path="select-provider" element={<SelectProvider />} />
21
+ <Route path="register" element={<RegistrationForm />} />
22
+ <Route path="select-plan" element={<SelectPlan />} />
23
+ <Route path="status" element={<Status />} />
24
+
25
+ {/* Optionally: a catch‐all “Not Found” */}
26
+ <Route
27
+ path="*"
28
+ element={
29
+ <div className="text-center text-red-500">
30
+ 404: Page Not Found
31
+ </div>
32
+ }
33
+ />
34
+ </Route>
35
+ </Routes>
36
+ </BrowserRouter>
37
+ )
38
+ }
39
+
40
+ export default InvoiceRegisterWidget
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="35.93" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 228"><path fill="#00D8FF" d="M210.483 73.824a171.49 171.49 0 0 0-8.24-2.597c.465-1.9.893-3.777 1.273-5.621c6.238-30.281 2.16-54.676-11.769-62.708c-13.355-7.7-35.196.329-57.254 19.526a171.23 171.23 0 0 0-6.375 5.848a155.866 155.866 0 0 0-4.241-3.917C100.759 3.829 77.587-4.822 63.673 3.233C50.33 10.957 46.379 33.89 51.995 62.588a170.974 170.974 0 0 0 1.892 8.48c-3.28.932-6.445 1.924-9.474 2.98C17.309 83.498 0 98.307 0 113.668c0 15.865 18.582 31.778 46.812 41.427a145.52 145.52 0 0 0 6.921 2.165a167.467 167.467 0 0 0-2.01 9.138c-5.354 28.2-1.173 50.591 12.134 58.266c13.744 7.926 36.812-.22 59.273-19.855a145.567 145.567 0 0 0 5.342-4.923a168.064 168.064 0 0 0 6.92 6.314c21.758 18.722 43.246 26.282 56.54 18.586c13.731-7.949 18.194-32.003 12.4-61.268a145.016 145.016 0 0 0-1.535-6.842c1.62-.48 3.21-.974 4.76-1.488c29.348-9.723 48.443-25.443 48.443-41.52c0-15.417-17.868-30.326-45.517-39.844Zm-6.365 70.984c-1.4.463-2.836.91-4.3 1.345c-3.24-10.257-7.612-21.163-12.963-32.432c5.106-11 9.31-21.767 12.459-31.957c2.619.758 5.16 1.557 7.61 2.4c23.69 8.156 38.14 20.213 38.14 29.504c0 9.896-15.606 22.743-40.946 31.14Zm-10.514 20.834c2.562 12.94 2.927 24.64 1.23 33.787c-1.524 8.219-4.59 13.698-8.382 15.893c-8.067 4.67-25.32-1.4-43.927-17.412a156.726 156.726 0 0 1-6.437-5.87c7.214-7.889 14.423-17.06 21.459-27.246c12.376-1.098 24.068-2.894 34.671-5.345a134.17 134.17 0 0 1 1.386 6.193ZM87.276 214.515c-7.882 2.783-14.16 2.863-17.955.675c-8.075-4.657-11.432-22.636-6.853-46.752a156.923 156.923 0 0 1 1.869-8.499c10.486 2.32 22.093 3.988 34.498 4.994c7.084 9.967 14.501 19.128 21.976 27.15a134.668 134.668 0 0 1-4.877 4.492c-9.933 8.682-19.886 14.842-28.658 17.94ZM50.35 144.747c-12.483-4.267-22.792-9.812-29.858-15.863c-6.35-5.437-9.555-10.836-9.555-15.216c0-9.322 13.897-21.212 37.076-29.293c2.813-.98 5.757-1.905 8.812-2.773c3.204 10.42 7.406 21.315 12.477 32.332c-5.137 11.18-9.399 22.249-12.634 32.792a134.718 134.718 0 0 1-6.318-1.979Zm12.378-84.26c-4.811-24.587-1.616-43.134 6.425-47.789c8.564-4.958 27.502 2.111 47.463 19.835a144.318 144.318 0 0 1 3.841 3.545c-7.438 7.987-14.787 17.08-21.808 26.988c-12.04 1.116-23.565 2.908-34.161 5.309a160.342 160.342 0 0 1-1.76-7.887Zm110.427 27.268a347.8 347.8 0 0 0-7.785-12.803c8.168 1.033 15.994 2.404 23.343 4.08c-2.206 7.072-4.956 14.465-8.193 22.045a381.151 381.151 0 0 0-7.365-13.322Zm-45.032-43.861c5.044 5.465 10.096 11.566 15.065 18.186a322.04 322.04 0 0 0-30.257-.006c4.974-6.559 10.069-12.652 15.192-18.18ZM82.802 87.83a323.167 323.167 0 0 0-7.227 13.238c-3.184-7.553-5.909-14.98-8.134-22.152c7.304-1.634 15.093-2.97 23.209-3.984a321.524 321.524 0 0 0-7.848 12.897Zm8.081 65.352c-8.385-.936-16.291-2.203-23.593-3.793c2.26-7.3 5.045-14.885 8.298-22.6a321.187 321.187 0 0 0 7.257 13.246c2.594 4.48 5.28 8.868 8.038 13.147Zm37.542 31.03c-5.184-5.592-10.354-11.779-15.403-18.433c4.902.192 9.899.29 14.978.29c5.218 0 10.376-.117 15.453-.343c-4.985 6.774-10.018 12.97-15.028 18.486Zm52.198-57.817c3.422 7.8 6.306 15.345 8.596 22.52c-7.422 1.694-15.436 3.058-23.88 4.071a382.417 382.417 0 0 0 7.859-13.026a347.403 347.403 0 0 0 7.425-13.565Zm-16.898 8.101a358.557 358.557 0 0 1-12.281 19.815a329.4 329.4 0 0 1-23.444.823c-7.967 0-15.716-.248-23.178-.732a310.202 310.202 0 0 1-12.513-19.846h.001a307.41 307.41 0 0 1-10.923-20.627a310.278 310.278 0 0 1 10.89-20.637l-.001.001a307.318 307.318 0 0 1 12.413-19.761c7.613-.576 15.42-.876 23.31-.876H128c7.926 0 15.743.303 23.354.883a329.357 329.357 0 0 1 12.335 19.695a358.489 358.489 0 0 1 11.036 20.54a329.472 329.472 0 0 1-11 20.722Zm22.56-122.124c8.572 4.944 11.906 24.881 6.52 51.026c-.344 1.668-.73 3.367-1.15 5.09c-10.622-2.452-22.155-4.275-34.23-5.408c-7.034-10.017-14.323-19.124-21.64-27.008a160.789 160.789 0 0 1 5.888-5.4c18.9-16.447 36.564-22.941 44.612-18.3ZM128 90.808c12.625 0 22.86 10.235 22.86 22.86s-10.235 22.86-22.86 22.86s-22.86-10.235-22.86-22.86s10.235-22.86 22.86-22.86Z"></path></svg>
@@ -0,0 +1,23 @@
1
+
2
+ type Props = {
3
+ title: string
4
+ isDisabled?: boolean
5
+ handleClick?: () => void
6
+ type?: 'submit' | 'button'
7
+ className?: string
8
+ }
9
+
10
+ const Button = (props: Props) => {
11
+ return (
12
+ <button
13
+ type={props.type || 'button'}
14
+ disabled={props.isDisabled}
15
+ className={`bg-green-500 hover:bg-green-600 text-white px-6 py-2 rounded disabled:opacity-50 *:disabled:cursor-not-allowed ${props.className}`}
16
+ onClick={props.handleClick}
17
+ >
18
+ {props.title}
19
+ </button>
20
+ )
21
+ }
22
+
23
+ export default Button
@@ -0,0 +1,20 @@
1
+ type Props = {
2
+ checked: boolean
3
+ setChecked: (checked: boolean) => void
4
+ }
5
+ const CustomCheckbox = ({ checked, setChecked }: Props) => {
6
+ return (
7
+ <label className='relative inline-flex cursor-pointer items-center'>
8
+ <input
9
+ type='checkbox'
10
+ className='peer sr-only'
11
+ checked={checked}
12
+ onChange={(e) => setChecked(e.target.checked)}
13
+ />
14
+
15
+ <div className='border-[#ACADAE] relative h-5 w-5 rounded-full border-2 before:absolute before:left-1/2 before:top-1/2 before:hidden before:h-2.5 before:w-2.5 before:-translate-x-1/2 before:-translate-y-1/2 before:rounded-full before:bg-green-500 peer-checked:border-green-500 peer-checked:before:block' />
16
+ </label>
17
+ )
18
+ }
19
+
20
+ export default CustomCheckbox
@@ -0,0 +1,141 @@
1
+ import { useCallback, useEffect, useRef, useState, type ChangeEvent } from "react";
2
+
3
+ type FileUploadProps = {
4
+ label: string;
5
+ required?: boolean;
6
+ file: File | null;
7
+ onFileChange: (file: File) => void;
8
+ error?: string;
9
+ };
10
+
11
+ const FileUpload: React.FC<FileUploadProps> = ({
12
+ label,
13
+ required = false,
14
+ file,
15
+ onFileChange,
16
+ error,
17
+ }) => {
18
+ const inputRef = useRef<HTMLInputElement>(null);
19
+ const [previewUrl, setPreviewUrl] = useState<string | null>(null);
20
+ const [isModalOpen, setModalOpen] = useState(false);
21
+
22
+ const handleFileInput = (e: ChangeEvent<HTMLInputElement>) => {
23
+ const chosen = e.target.files?.[0];
24
+ if (!chosen) return;
25
+ onFileChange(chosen);
26
+ setPreviewUrl(URL.createObjectURL(chosen));
27
+ };
28
+
29
+ const openPicker = useCallback(() => {
30
+ inputRef.current?.click();
31
+ }, []);
32
+
33
+ useEffect(() => {
34
+ if(file){
35
+ setPreviewUrl(URL.createObjectURL(file as File))
36
+ }
37
+ }, [file])
38
+
39
+ return (
40
+ <>
41
+ {/* Label + Upload button */}
42
+ <div className="flex flex-col">
43
+ <label className="font-medium mb-1 text-gray-700">
44
+ {label}{required && <span className="text-red-500 ml-1">*</span>}
45
+ </label>
46
+ <div className="flex items-center">
47
+ <button
48
+ type="button"
49
+ onClick={openPicker}
50
+ className="bg-green-500 hover:bg-green-600 text-white px-4 py-2 rounded"
51
+ >
52
+ Upload file
53
+ </button>
54
+ <input
55
+ ref={inputRef}
56
+ type="file"
57
+ accept="image/*,.pdf"
58
+ className="hidden"
59
+ onChange={handleFileInput}
60
+ />
61
+ </div>
62
+
63
+ {/* Preview box */}
64
+ <div
65
+ className="mt-2 h-40 w-full bg-gray-200 rounded overflow-hidden flex items-center justify-center cursor-pointer"
66
+ onClick={() => previewUrl && setModalOpen(true)}
67
+ >
68
+ {previewUrl ? (
69
+ file?.type === 'application/pdf' ? (
70
+ <object
71
+ data={previewUrl}
72
+ type="application/pdf"
73
+ width="100%"
74
+ height="100%"
75
+ >
76
+ <p className="text-gray-600 text-sm">
77
+ Cannot preview PDF.{' '}
78
+ <a
79
+ href={previewUrl}
80
+ target="_blank"
81
+ rel="noreferrer"
82
+ className="text-blue-600 underline"
83
+ >
84
+ Download PDF
85
+ </a>
86
+ </p>
87
+ </object>
88
+ ) : (
89
+ <img
90
+ src={previewUrl}
91
+ alt="Preview"
92
+ className="h-full object-contain"
93
+ />
94
+ )
95
+ ) : (
96
+ <span className="text-gray-500">No file selected</span>
97
+ )}
98
+ </div>
99
+
100
+ {error && <span className="text-red-500 text-sm mt-1">{error}</span>}
101
+ </div>
102
+
103
+ {/* Lightbox Modal */}
104
+ {isModalOpen && previewUrl && (
105
+ <div
106
+ className="fixed inset-0 bg-black bg-opacity-75 z-50 flex items-center justify-center"
107
+ onClick={() => setModalOpen(false)}
108
+ >
109
+ <div
110
+ className="relative w-full h-full"
111
+ onClick={(e) => e.stopPropagation()}
112
+ >
113
+ <button
114
+ onClick={() => setModalOpen(false)}
115
+ className="absolute top-2 right-2 text-white text-2xl"
116
+ aria-label="Close preview"
117
+ >
118
+ &times;
119
+ </button>
120
+
121
+ {file?.type === 'application/pdf' ? (
122
+ <object
123
+ data={previewUrl}
124
+ type="application/pdf"
125
+ className="w-full h-full object-contain"
126
+ />
127
+ ) : (
128
+ <img
129
+ src={previewUrl}
130
+ alt="Full Preview"
131
+ className="w-full h-full object-contain"
132
+ />
133
+ )}
134
+ </div>
135
+ </div>
136
+ )}
137
+ </>
138
+ );
139
+ };
140
+
141
+ export default FileUpload;
@@ -0,0 +1,35 @@
1
+ import { forwardRef } from "react";
2
+
3
+ type InputFieldProps = {
4
+ label: string;
5
+ required?: boolean;
6
+ error?: string;
7
+ } & React.InputHTMLAttributes<HTMLInputElement>;
8
+
9
+ const InputField = forwardRef<HTMLInputElement, InputFieldProps>(
10
+ ({ label, required = false, error, ...props }, ref) => (
11
+ <div className="flex flex-col">
12
+ <label
13
+ htmlFor={props.name}
14
+ className="font-medium mb-1 text-gray-700"
15
+ >
16
+ {label}
17
+ {required && <span className="text-red-500 ml-1">*</span>}
18
+ </label>
19
+ <input
20
+ id={props.name}
21
+ ref={ref}
22
+ {...props}
23
+ className={`border rounded px-3 py-2 focus:outline-none focus:ring-2 focus:ring-blue-500 ${
24
+ error ? 'border-red-500' : 'border-gray-300'
25
+ }`}
26
+ />
27
+ {error && (
28
+ <span className="text-red-500 text-sm mt-1">{error}</span>
29
+ )}
30
+ </div>
31
+ )
32
+ );
33
+ InputField.displayName = 'InputField';
34
+
35
+ export default InputField;
@@ -0,0 +1,74 @@
1
+ import React from 'react';
2
+
3
+ type Option = {
4
+ value: string;
5
+ label: string;
6
+ };
7
+
8
+ type SubscriptionSelectorProps = {
9
+ options: Option[];
10
+ value: string;
11
+ onChange: (value: string) => void;
12
+ };
13
+
14
+ const SubscriptionSelector: React.FC<SubscriptionSelectorProps> = ({
15
+ options,
16
+ value,
17
+ onChange,
18
+ }) => {
19
+ return (
20
+ <fieldset
21
+ role="radiogroup"
22
+ aria-label="Chọn gói đăng ký"
23
+ className="flex flex-col md:flex-row gap-4 md:gap-20"
24
+ >
25
+ {options.map((opt) => {
26
+ const selected = opt.value === value;
27
+ return (
28
+ <label
29
+ key={opt.value}
30
+ className={[
31
+ 'flex items-center cursor-pointer rounded-lg border p-4 transition',
32
+ selected
33
+ ? 'border-green-500 bg-green-50'
34
+ : 'border-gray-300 bg-white hover:bg-gray-50',
35
+ ].join(' ')}
36
+ >
37
+ {/* Visually hidden native radio */}
38
+ <input
39
+ type="radio"
40
+ name="subscription"
41
+ value={opt.value}
42
+ checked={selected}
43
+ onChange={() => onChange(opt.value)}
44
+ className="sr-only"
45
+ />
46
+
47
+ {/* Custom radio visual */}
48
+ <span
49
+ className={[
50
+ 'flex-shrink-0 flex items-center justify-center rounded-full mr-3',
51
+ selected
52
+ ? 'w-5 h-5 border-2 border-green-500 bg-green-500'
53
+ : 'w-4 h-4 border border-gray-400',
54
+ ].join(' ')}
55
+ >
56
+ {selected && (
57
+ <span className="block w-2 h-2 bg-white rounded-full" />
58
+ )}
59
+ </span>
60
+
61
+ {/* Label text */}
62
+ <span
63
+ className={selected ? 'text-green-700 font-medium' : 'text-gray-700'}
64
+ >
65
+ {opt.label}
66
+ </span>
67
+ </label>
68
+ );
69
+ })}
70
+ </fieldset>
71
+ );
72
+ };
73
+
74
+ export default SubscriptionSelector;
@@ -0,0 +1,14 @@
1
+ import { Outlet } from "react-router-dom"
2
+ import Process from "./process"
3
+
4
+
5
+ const MainLayout = () => {
6
+ return (
7
+ <div className="max-w-[800px] mx-auto py-10 flex flex-col gap-8">
8
+ <Process />
9
+ <Outlet />
10
+ </div>
11
+ )
12
+ }
13
+
14
+ export default MainLayout
@@ -0,0 +1,21 @@
1
+ import { useProcessStore } from "../store/process";
2
+
3
+
4
+ const MAX_STEP = 4;
5
+
6
+ const Process = () => {
7
+ const { step } = useProcessStore();
8
+ return (
9
+ <div className="w-full relative h-3 bg-gray-200 rounded-full">
10
+ <div className="absolute rounded-full bg-green-500"
11
+ style={{
12
+ width: `${(step / MAX_STEP) * 100}%`,
13
+ height: '100%',
14
+ transition: 'width 0.3s ease-in-out'
15
+ }}
16
+ ></div>
17
+ </div>
18
+ )
19
+ }
20
+
21
+ export default Process
package/src/index.css ADDED
@@ -0,0 +1,2 @@
1
+ @import "tailwindcss";
2
+
package/src/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ import InvoiceRegisterWidget from './App'
2
+ export default InvoiceRegisterWidget;
package/src/main.tsx ADDED
@@ -0,0 +1,10 @@
1
+ import { StrictMode } from 'react'
2
+ import { createRoot } from 'react-dom/client'
3
+ import InvoiceRegisterWidget from './App'
4
+ import './index.css'
5
+
6
+ createRoot(document.getElementById('root')!).render(
7
+ <StrictMode>
8
+ <InvoiceRegisterWidget />
9
+ </StrictMode>,
10
+ )
@@ -0,0 +1,222 @@
1
+ import { zodResolver } from '@hookform/resolvers/zod';
2
+ import type { SubmitHandler } from 'react-hook-form';
3
+ import { Controller, useForm } from 'react-hook-form';
4
+ import { useNavigate } from 'react-router-dom';
5
+ import z from "zod";
6
+ import Button from '../components/button';
7
+ import FileUpload from '../components/form/file-upload';
8
+ import InputField from '../components/form/input-field';
9
+ import { useProcessStore } from '../store/process';
10
+ import { useRegisterStore } from '../store/register';
11
+
12
+ const formSchema = z.object({
13
+ taxCode: z.string().nonempty('Mã số thuế là bắt buộc'),
14
+ representative: z.string().nonempty('Người đại diện là bắt buộc'),
15
+ email: z
16
+ .string()
17
+ .nonempty('Email là bắt buộc')
18
+ .email('Email không hợp lệ'),
19
+ address: z.string().nonempty('Địa chỉ là bắt buộc'),
20
+ companyName: z.string().nonempty('Tên công ty là bắt buộc'),
21
+ position: z.string().optional(),
22
+ phone: z
23
+ .string()
24
+ .regex(/^[0-9()+\-\s]+$/, 'SĐT không hợp lệ')
25
+ .optional(),
26
+
27
+ // ← here we make it `.optional()`
28
+ license: z
29
+ .instanceof(File, {
30
+ message: 'Giấy phép đăng ký kinh doanh là bắt buộc',
31
+ })
32
+ .optional(),
33
+ });
34
+
35
+ export type FormValues = z.infer<typeof formSchema>;
36
+
37
+
38
+ const RegistrationForm = () => {
39
+ const navigate = useNavigate();
40
+ const form = useRegisterStore((state) => state.form);
41
+ const {
42
+ control,
43
+ handleSubmit,
44
+ formState: { errors, isSubmitting, isValid },
45
+ } = useForm<FormValues>({
46
+ resolver: zodResolver(formSchema),
47
+ defaultValues: {
48
+ taxCode: form.taxCode || '',
49
+ representative: form.representative || '',
50
+ email: form.email || '',
51
+ address: form.address || '',
52
+ companyName: form.companyName || '',
53
+ position: form.position || '',
54
+ phone: form.phoneNumber || '',
55
+ license: form.license || undefined, // handle optional license
56
+ },
57
+ });
58
+
59
+ const setForm = useRegisterStore((state) => state.setForm);
60
+ const nextStep = useProcessStore((state) => state.nextStep);
61
+ const prevStep = useProcessStore((state) => state.prevStep);
62
+
63
+ const onSubmit: SubmitHandler<FormValues> = (data) => {
64
+ // here data.license is a File
65
+ console.log(data);
66
+
67
+ setForm({
68
+ taxCode: data.taxCode,
69
+ representative: data.representative,
70
+ email: data.email,
71
+ address: data.address,
72
+ companyName: data.companyName,
73
+ position: data.position,
74
+ phoneNumber: data.phone || null, // handle optional phone
75
+ license: data.license || null, // handle optional license
76
+ });
77
+
78
+ };
79
+
80
+ return (
81
+ <form
82
+ onSubmit={handleSubmit(onSubmit)}
83
+ className="w-full mx-auto p-6 bg-white shadow rounded"
84
+ >
85
+ <div className="grid grid-cols-1 md:grid-cols-2 gap-8">
86
+ {/* Left */}
87
+ <div className="space-y-4">
88
+ <Controller
89
+ name="taxCode"
90
+ control={control}
91
+ render={({ field }) => (
92
+ <InputField
93
+ {...field}
94
+ label="Mã số thuế"
95
+ required
96
+ error={errors.taxCode?.message}
97
+ />
98
+ )}
99
+ />
100
+
101
+ <Controller
102
+ name="representative"
103
+ control={control}
104
+ render={({ field }) => (
105
+ <InputField
106
+ {...field}
107
+ label="Người đại diện"
108
+ required
109
+ error={errors.representative?.message}
110
+ />
111
+ )}
112
+ />
113
+
114
+ <Controller
115
+ name="email"
116
+ control={control}
117
+ render={({ field }) => (
118
+ <InputField
119
+ {...field}
120
+ label="Email"
121
+ type="email"
122
+ required
123
+ error={errors.email?.message}
124
+ />
125
+ )}
126
+ />
127
+
128
+ <Controller
129
+ name="address"
130
+ control={control}
131
+ render={({ field }) => (
132
+ <InputField
133
+ {...field}
134
+ label="Địa chỉ"
135
+ required
136
+ error={errors.address?.message}
137
+ />
138
+ )}
139
+ />
140
+
141
+ <Controller
142
+ name="license"
143
+ control={control}
144
+ render={({ field }) => (
145
+ <FileUpload
146
+ label="Giấy phép đăng ký kinh doanh"
147
+ required
148
+ file={field.value ?? null}
149
+ onFileChange={field.onChange}
150
+ error={errors.license?.message}
151
+ />
152
+ )}
153
+ />
154
+ </div>
155
+
156
+ {/* Right */}
157
+ <div className="space-y-4">
158
+ <Controller
159
+ name="companyName"
160
+ control={control}
161
+ render={({ field }) => (
162
+ <InputField
163
+ {...field}
164
+ label="Tên công ty"
165
+ required
166
+ error={errors.companyName?.message}
167
+ />
168
+ )}
169
+ />
170
+
171
+ <Controller
172
+ name="position"
173
+ control={control}
174
+ render={({ field }) => (
175
+ <InputField
176
+ {...field}
177
+ label="Chức vụ"
178
+ error={errors.position?.message}
179
+ />
180
+ )}
181
+ />
182
+
183
+ <Controller
184
+ name="phone"
185
+ control={control}
186
+ render={({ field }) => (
187
+ <InputField
188
+ {...field}
189
+ label="SĐT"
190
+ type="tel"
191
+ error={errors.phone?.message}
192
+ />
193
+ )}
194
+ />
195
+ </div>
196
+ </div>
197
+
198
+ <div className='flex items-center justify-end gap-2'>
199
+ <Button title={'Back'}
200
+ handleClick={() => {
201
+ prevStep()
202
+ navigate('/select-provider');
203
+ }
204
+ }
205
+
206
+ className=' !bg-gray-200 !text-gray-700 hover:!bg-gray-300 disabled:!bg-gray-200 disabled:!text-gray-500'
207
+ />
208
+ <Button
209
+ type='submit'
210
+ title={isSubmitting ? 'Submitting...' : 'Submit'} isDisabled={isSubmitting || Object.keys(errors).length > 0 || !isValid}
211
+ handleClick={() => {
212
+ nextStep()
213
+ navigate('/select-plan');
214
+ }
215
+ }
216
+ />
217
+ </div>
218
+ </form>
219
+ );
220
+ };
221
+
222
+ export default RegistrationForm;
@@ -0,0 +1,39 @@
1
+ import { useState } from "react";
2
+ import { useNavigate } from "react-router-dom";
3
+ import Button from "../components/button";
4
+ import SubscriptionSelector from "../components/form/select-option";
5
+ import { useProcessStore } from "../store/process";
6
+
7
+
8
+ const SelectPlan = () => {
9
+ const navigate = useNavigate();
10
+ const nextStep = useProcessStore((state) => state.nextStep);
11
+ const [plan, setPlan] = useState('300');
12
+ const options = [
13
+ { value: '100', label: '100 đơn/tháng' },
14
+ { value: '300', label: '300 đơn/tháng' },
15
+ { value: '500', label: '500 đơn/tháng' },
16
+ ];
17
+
18
+ return (
19
+ <div className="w-full flex flex-col gap-6">
20
+ <h2 className="heading">Select subscription package</h2>
21
+ <SubscriptionSelector
22
+ options={options}
23
+ value={plan}
24
+ onChange={setPlan}
25
+ />
26
+ <div className='text-right'>
27
+ <Button title={'Next'}
28
+ isDisabled={!plan}
29
+ handleClick={() => {
30
+ nextStep()
31
+ navigate("/status")
32
+ }}
33
+ />
34
+ </div>
35
+ </div>
36
+ );
37
+ }
38
+
39
+ export default SelectPlan;
@@ -0,0 +1,74 @@
1
+ import { useNavigate } from "react-router-dom";
2
+ import Button from "../components/button";
3
+ import CustomCheckbox from "../components/form/custom-checkbox";
4
+ import { useProcessStore } from "../store/process";
5
+ import { useRegisterStore } from "../store/register";
6
+
7
+
8
+
9
+ interface IProvider {
10
+ name: string;
11
+ route: string;
12
+ };
13
+
14
+ const providers: IProvider[] = [
15
+ { name: 'M-Invoice', route: 'm-invoice' },
16
+ { name: 'FPT', route: 'fpt' },
17
+ { name: 'Misa', route: 'misa' },
18
+ ];
19
+
20
+ const ProviderItem = ({ provider, handleProviderChange }: { provider: IProvider,
21
+ handleProviderChange: (provider: string) => void
22
+ } ) => {
23
+ const selectedProvider = useRegisterStore((state) => state.selectedProvider)
24
+ return (
25
+ <div
26
+ data-checked={selectedProvider === provider.route}
27
+ className="flex items-center justify-center gap-2 px-4 py-2 border border-gray-300 rounded-md hover:bg-gray-100 cursor-pointer
28
+ transition-colors duration-200 data-[checked=true]:border-green-500 data-[checked=true]:text-green-700
29
+ "
30
+ onClick={() => handleProviderChange(provider.route)}
31
+ >
32
+ <CustomCheckbox checked={selectedProvider === provider.route}
33
+ setChecked={() => handleProviderChange(provider.route)}
34
+ />
35
+ <label className="">{provider.name}</label>
36
+ </div>
37
+ )
38
+ }
39
+
40
+ const SelectProvider = () => {
41
+
42
+ const navigate = useNavigate()
43
+ const selectedProvider = useRegisterStore((state) => state.selectedProvider);
44
+ const setSelectedProvider = useRegisterStore((state) => state.setSelectedProvider);
45
+ const nextStep = useProcessStore(state => state.nextStep);
46
+
47
+ const handleProviderChange = (provider: string) => {
48
+ setSelectedProvider(provider);
49
+ };
50
+
51
+ return (
52
+ <div className="w-full flex flex-col gap-6">
53
+ <h2 className="heading">Select Provider</h2>
54
+ <div className="flex gap-20">
55
+ {
56
+ providers.map((provider) => (
57
+ <ProviderItem key={provider.route} provider={provider} handleProviderChange={handleProviderChange} />
58
+ ))
59
+ }
60
+ </div>
61
+ <div className='text-right'>
62
+ <Button title={'Next'}
63
+ isDisabled={!selectedProvider}
64
+ handleClick={() => {
65
+ nextStep()
66
+ navigate("/register")
67
+ }}
68
+ />
69
+ </div>
70
+ </div>
71
+ )
72
+ }
73
+
74
+ export default SelectProvider
@@ -0,0 +1,9 @@
1
+
2
+
3
+ const Status = () => {
4
+ return (
5
+ <div>Status</div>
6
+ )
7
+ }
8
+
9
+ export default Status
@@ -0,0 +1,18 @@
1
+ import {create} from 'zustand';
2
+
3
+ type State = {
4
+ step: number;
5
+
6
+ }
7
+
8
+ type Actions = {
9
+ nextStep: () => void
10
+ prevStep: () => void
11
+ }
12
+
13
+ export const useProcessStore = create<State & Actions>((set) => ({
14
+ step: 1,
15
+ nextStep: () => set((state) => ({ step: state.step + 1 })),
16
+ prevStep: () => set((state) => ({ step: Math.max(state.step - 1, 1) })),
17
+ reset: () => set({ step: 1})
18
+ }));
@@ -0,0 +1,60 @@
1
+ import {create } from 'zustand';
2
+
3
+ type State = {
4
+ selectedProvider: string | null;
5
+ form: {
6
+ taxCode: string;
7
+ companyName: string;
8
+ representative: string;
9
+ position: string;
10
+ email: string;
11
+ phoneNumber: string | null;
12
+ address: string ;
13
+ license: File | null;
14
+ },
15
+ selectedPlan: string | null;
16
+ }
17
+
18
+ type Actions = {
19
+ setSelectedProvider: (provider: string | null) => void;
20
+ setForm: (form: Partial<State['form']>) => void;
21
+ setSelectedPlan: (plan: string | null) => void;
22
+ reset: () => void;
23
+ }
24
+ export const useRegisterStore = create<State & Actions>((set) => ({
25
+ selectedProvider: null,
26
+ form: {
27
+ taxCode: '',
28
+ companyName: '',
29
+ representative: '',
30
+ position: '',
31
+ email: '',
32
+ phoneNumber: null,
33
+ address: '',
34
+ license: null,
35
+ },
36
+ selectedPlan: null,
37
+
38
+ setSelectedProvider: (provider) => set({ selectedProvider: provider }),
39
+
40
+ setForm: (form) => set((state) => ({
41
+ form: { ...state.form, ...form }
42
+ })),
43
+
44
+ setSelectedPlan: (plan) => set({ selectedPlan: plan }),
45
+
46
+ reset: () => set({
47
+ selectedProvider: null,
48
+ form: {
49
+ taxCode: '',
50
+ companyName: '',
51
+ representative: '',
52
+ position: '',
53
+ email: '',
54
+ phoneNumber: null,
55
+ address: '',
56
+ license: null,
57
+ },
58
+ selectedPlan: null,
59
+ }),
60
+ }));
@@ -0,0 +1 @@
1
+ /// <reference types="vite/client" />
package/tsconfig.json ADDED
@@ -0,0 +1,19 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2019",
4
+ "module": "CommonJS",
5
+ "jsx": "react-jsx",
6
+ "outDir": "dist",
7
+ "rootDir": "src",
8
+ "strict": true,
9
+ "declaration": true,
10
+ "declarationMap": true,
11
+ "sourceMap": true,
12
+ "esModuleInterop": true,
13
+ "forceConsistentCasingInFileNames": true,
14
+ "skipLibCheck": true,
15
+ "emitDeclarationOnly": true,
16
+ },
17
+ "include": ["src/**/*"],
18
+ "exclude": ["node_modules", "dist"]
19
+ }
@@ -0,0 +1 @@
1
+ {"root":["./src/app.tsx","./src/index.ts","./src/main.tsx","./src/vite-env.d.ts","./src/components/button.tsx","./src/components/layout.tsx","./src/components/process.tsx","./src/components/form/custom-checkbox.tsx","./src/components/form/file-upload.tsx","./src/components/form/input-field.tsx","./src/components/form/select-option.tsx","./src/pages/register.tsx","./src/pages/select-plan.tsx","./src/pages/select-provider.tsx","./src/pages/status.tsx","./src/store/process.ts","./src/store/register.ts"],"version":"5.8.3"}
package/vite.config.ts ADDED
@@ -0,0 +1,46 @@
1
+ import { defineConfig } from 'vite'
2
+ import react from '@vitejs/plugin-react'
3
+ import tailwindcss from '@tailwindcss/vite'
4
+ import autoprefixer from 'autoprefixer'
5
+ import path from 'path'
6
+ // https://vite.dev/config/
7
+ export default defineConfig({
8
+ root: ".",
9
+ resolve: {
10
+ alias: {
11
+ "@": path.resolve(__dirname, "./src"),
12
+ },
13
+ },
14
+ build: {
15
+ outDir: "dist",
16
+ lib: {
17
+ entry: path.resolve(__dirname, "src/index.ts"),
18
+ name: "SdkWidget",
19
+ formats: ["es", "cjs"],
20
+ fileName: (format) => `index.${format}.js`,
21
+ },
22
+ rollupOptions: {
23
+ // Do not bundle React/ReactDOM/ReactRouter – treat them as externals
24
+ external: ["react", "react-dom", "react-router-dom"],
25
+ output: {
26
+ globals: {
27
+ react: "React",
28
+ "react-dom": "ReactDOM",
29
+ "react-router-dom": "ReactRouterDOM",
30
+ },
31
+ },
32
+ },
33
+ },
34
+ server: {
35
+ port: 3000,
36
+ open: true,
37
+ },
38
+ plugins: [react(),tailwindcss(),],
39
+ css: {
40
+ postcss: {
41
+ plugins: [
42
+ autoprefixer(),
43
+ ]
44
+ }
45
+ }
46
+ })