Skip to content

Commit

Permalink
Merge branch 'main' into feature/PW-251-shared-components
Browse files Browse the repository at this point in the history
  • Loading branch information
Legitgoons authored Apr 28, 2024
2 parents 74aa30c + e5bcdc9 commit 053f65b
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
dist
.eslintrc.cjs
mocks
mocks
index.d.ts
6 changes: 6 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,9 @@ declare module '*.svg' {
const content: React.FC<React.SVGProps<SVGElement>>;
export default content;
}

export declare global {
interface Window {
setAccessToken: (accessToken: string) => void;
}
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"axios": "^1.6.7",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "6.22.2"
"react-router-dom": "6.22.2",
"zustand": "^4.5.2"
},
"devDependencies": {
"@tanstack/eslint-plugin-query": "^5.28.11",
Expand Down
5 changes: 5 additions & 0 deletions src/app/webview/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { setAccessToken } from '@/shared/store';

export function initWebViewInfo() {
window.setAccessToken = setAccessToken;
}
2 changes: 2 additions & 0 deletions src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import ReactDOM from 'react-dom/client';

import App from './app/App';
import { initWebViewInfo } from './app/webview';

async function enableMocking() {
if (import.meta.env.PROD) {
Expand All @@ -13,5 +14,6 @@ async function enableMocking() {
}

enableMocking().then(() => {
initWebViewInfo();
ReactDOM.createRoot(document.getElementById('root')!).render(<App />);
});
23 changes: 23 additions & 0 deletions src/shared/store/auth/auth-store.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { create } from 'zustand';
import { devtools } from 'zustand/middleware';

interface AuthState {
accessToken: string | undefined;
}

const useAuthStore = create<AuthState>()(
devtools(
(): AuthState => ({
accessToken: undefined,
}),
{ name: 'auth-store' },
),
);

export function setAccessToken(accessToken: string) {
useAuthStore.setState(() => ({ accessToken }), false, 'auth/setAccessToken');
}

export function getAccessToken() {
return useAuthStore.getState().accessToken;
}
1 change: 1 addition & 0 deletions src/shared/store/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { setAccessToken, getAccessToken } from './auth/auth-store';
12 changes: 12 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4226,6 +4226,11 @@ url-parse@^1.5.3:
querystringify "^2.1.1"
requires-port "^1.0.0"

[email protected]:
version "1.2.0"
resolved "https://registry.yarnpkg.com/use-sync-external-store/-/use-sync-external-store-1.2.0.tgz#7dbefd6ef3fe4e767a0cf5d7287aacfb5846928a"
integrity sha512-eEgnFxGQ1Ife9bzYs6VLi8/4X6CObHMw9Qr9tPY43iKwsPw8xE8+EFsf/2cFZ5S3esXgpWgtSCtLNS41F+sKPA==

[email protected]:
version "1.5.0"
resolved "https://registry.yarnpkg.com/vite-node/-/vite-node-1.5.0.tgz#7f74dadfecb15bca016c5ce5ef85e5cc4b82abf2"
Expand Down Expand Up @@ -4474,3 +4479,10 @@ yocto-queue@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/yocto-queue/-/yocto-queue-1.0.0.tgz#7f816433fb2cbc511ec8bf7d263c3b58a1a3c251"
integrity sha512-9bnSc/HEW2uRy67wc+T8UwauLuPJVn28jb+GtJY16iiKWyvmYJRXVT4UamsAEGQfPohgr2q4Tq0sQbQlxTfi1g==

zustand@^4.5.2:
version "4.5.2"
resolved "https://registry.yarnpkg.com/zustand/-/zustand-4.5.2.tgz#fddbe7cac1e71d45413b3682cdb47b48034c3848"
integrity sha512-2cN1tPkDVkwCy5ickKrI7vijSjPksFRfqS6237NzT0vqSsztTNnQdHw9mmN7uBdk3gceVXU0a+21jFzFzAc9+g==
dependencies:
use-sync-external-store "1.2.0"

0 comments on commit 053f65b

Please sign in to comment.