@campxdev/shared 0.5.4 → 0.5.6

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.
@@ -1,82 +1,84 @@
1
- import { useEffect, useState } from "react";
2
- import { useQuery } from "react-query";
3
- import { toast } from "react-toastify";
4
- import axios from "../config/axios";
5
- import { isDevelopment } from "../constants";
6
- import { useLoginForm } from "../contexts/LoginFormProvider";
7
- import { PermissionsStore } from "../permissions";
8
- import { AssetsStore, UserStore } from "../shared-state";
1
+ import {useEffect, useState} from 'react'
2
+ import {useQuery} from 'react-query'
3
+ import {toast} from 'react-toastify'
4
+ import axios from '../config/axios'
5
+ import {isDevelopment} from '../constants'
6
+ import {useLoginForm} from '../contexts/LoginFormProvider'
7
+ import {PermissionsStore} from '../permissions'
8
+ import {AssetsStore, UserStore} from '../shared-state'
9
9
 
10
- const url = window.location.origin;
10
+ const url = window.location.origin
11
11
 
12
12
  function useAuth(): {
13
- loading: boolean;
14
- data: {
15
- user?: any;
16
- roles?: any;
17
- username?: any;
18
- permissions?: any;
19
- assets?: {
20
- logo: string;
21
- logo_square: string;
22
- };
23
- };
13
+ loading: boolean
14
+ data: {
15
+ user?: any
16
+ roles?: any
17
+ username?: any
18
+ permissions?: any
19
+ assets?: {
20
+ logo: string
21
+ logo_square: string
22
+ }
23
+ }
24
24
  } {
25
- const { openLoginForm } = useLoginForm();
26
- const [loading, setLoading] = useState<boolean>(false);
27
- const [data, setData] = useState(null);
28
- const [payLogo, setPayLogo] = useState(null);
29
- const appInit = async () => {
30
- setLoading(true);
25
+ const {openLoginForm} = useLoginForm()
26
+ const [loading, setLoading] = useState<boolean>(false)
27
+ const [data, setData] = useState(null)
28
+ const appInit = async () => {
29
+ setLoading(true)
31
30
 
32
- axios
33
- .get("/auth/my-permissions")
34
- .then((res) => {
35
- console.log(res.data);
36
- setLoading(false);
37
- setData(res.data);
38
- UserStore.update((s) => {
39
- s.username = res.data?.username;
40
- s.user = res.data?.user;
41
- s.roles = res.data?.roles;
42
- });
31
+ axios
32
+ .get('/auth/my-permissions')
33
+ .then((res) => {
34
+ console.log(res.data)
35
+ setLoading(false)
36
+ setData(res.data)
37
+ UserStore.update((s) => {
38
+ s.username = res.data?.username
39
+ s.user = res.data?.user
40
+ s.roles = res.data?.roles
41
+ })
43
42
 
44
- PermissionsStore.update((s) => {
45
- s.permissions = {
46
- ...res.data?.permissions,
47
- can_settings_view: 1,
48
- can_dashboard_view: 1,
49
- can_individual_pages_view: 1,
50
- } as any;
51
- });
52
- AssetsStore.update((s) => {
53
- s.logo = res.data?.assets.logo;
54
- s.logo_square = res.data?.assets.logo_square;
55
- });
56
- })
57
- .catch((err) => {
58
- setLoading(false);
59
- if (err.response.status !== 401) {
60
- toast.error("Server Error");
61
- }
62
- if (isDevelopment) {
63
- openLoginForm();
64
- } else {
65
- window.location.replace(
66
- `https://www.id.campx.in/?redirect_to=${url}`
67
- );
68
- }
69
- });
70
- };
43
+ PermissionsStore.update((s) => {
44
+ s.permissions = {
45
+ ...res.data?.permissions,
46
+ can_settings_view: 1,
47
+ can_dashboard_view: 1,
48
+ can_individual_pages_view: 1,
49
+ } as any
50
+ })
51
+ AssetsStore.update((s) => {
52
+ s.logo = res.data?.assets.logo
53
+ s.logo_square = res.data?.assets.logo_square
54
+ })
55
+ })
56
+ .catch((err) => {
57
+ setLoading(false)
58
+ if (err.response.status !== 401) {
59
+ toast.error('Server Error')
60
+ }
61
+ if (isDevelopment) {
62
+ openLoginForm()
63
+ } else {
64
+ window.location.replace(`https://www.id.campx.in/?redirect_to=${url}`)
65
+ }
66
+ })
67
+ }
71
68
 
72
- useEffect(() => {
73
- appInit();
74
- }, []);
69
+ useEffect(() => {
70
+ if (window.location.pathname === '/') {
71
+ if (isDevelopment) {
72
+ window.location.replace(window.location.origin + '/campx_dev')
73
+ }
74
+ }
75
+ appInit()
76
+ }, [])
75
77
 
76
- return {
77
- loading: loading || !data?.permissions,
78
- data,
79
- };
78
+ return {
79
+ loading: loading || !data?.permissions,
80
+ data,
81
+ }
80
82
  }
81
83
 
82
- export default useAuth;
84
+ export default useAuth