blob: 92e3956c79a58769216a3265c4e611a3b37eeb0c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
|
import Divider from '@/core/components/elements/Divider/Divider';
import AppLayout from '@/core/components/layouts/AppLayout';
import BasicLayout from '@/core/components/layouts/BasicLayout';
import DesktopView from '@/core/components/views/DesktopView';
import MobileView from '@/core/components/views/MobileView';
import useAuth from '@/core/hooks/useAuth';
import CompanyProfile from '@/lib/auth/components/CompanyProfile';
import SwitchAccount from '@/lib/auth/components/SwitchAccount';
import IsAuth from '@/lib/auth/components/IsAuth';
import Menu from '@/lib/auth/components/Menu';
import PersonalProfile from '@/lib/auth/components/PersonalProfile';
// import StatusSwitchAccount from '@/lib/auth/components/StatusSwitchAccount';
import { Checkbox } from '@chakra-ui/react';
import { useState, useEffect } from 'react';
import switchAccountProgresApi from '@/lib/auth/api/switchAccountProgresApi.js';
import BottomPopup from '@/core/components/elements/Popup/BottomPopup';
import { useRouter } from 'next/router';
export default function Profile() {
const auth = useAuth();
// console.log('auth', auth);
const [isChecked, setIsChecked] = useState(false);
const [ubahAkun, setUbahAkun] = useState(false);
const [isAprove, setIsAprove] = useState();
const [changeConfirmation, setChangeConfirmation] = useState(false);
const router = useRouter();
// Handle checkbox toggle
const handleChange = () => {
if (isChecked) {
setIsChecked(false);
} else {
setChangeConfirmation(true);
}
};
// Load status dan cek localStorage "autoCheckProfile"
useEffect(() => {
const loadPromo = async () => {
const progresSwitchAccount = await switchAccountProgresApi();
if (progresSwitchAccount) {
setIsAprove(progresSwitchAccount.status);
setUbahAkun(progresSwitchAccount.status);
}
};
loadPromo();
if (typeof window !== 'undefined') {
const autoCheck = localStorage.getItem('autoCheckProfile');
if (autoCheck === 'true') {
setIsChecked(true);
localStorage.removeItem('autoCheckProfile');
// Hapus query param supaya URL bersih
if (router.query.autoCheck) {
const cleanQuery = { ...router.query };
delete cleanQuery.autoCheck;
router.replace(
{ pathname: router.pathname, query: cleanQuery },
undefined,
{ shallow: true }
);
}
}
}
}, [router]);
// Confirm checkbox change from popup
const handleConfirmSubmit = () => {
setChangeConfirmation(false);
setIsChecked(true);
};
return (
<>
<BottomPopup
active={changeConfirmation}
close={() => setChangeConfirmation(false)} //Menutup popup
title="Ubah type akun"
>
<div className="leading-7 text-gray_r-12/80">
Anda akan mengubah type akun anda?
</div>
<div className="flex mt-6 gap-x-4 md:justify-end">
<button
className="btn-solid-red flex-1 md:flex-none"
type="button"
onClick={handleConfirmSubmit}
>
Yakin
</button>
<button
className="btn-light flex-1 md:flex-none"
type="button"
onClick={() => setChangeConfirmation(false)}
>
Batal
</button>
</div>
</BottomPopup>
<IsAuth>
<MobileView>
<AppLayout title="Akun Saya">
{auth?.company || ((isChecked || (!ubahAkun && ubahAkun !== 'pending')) && (
<div className="text-sm p-4 flex items-center">
<Checkbox
borderColor="gray.600"
colorScheme="red"
size="lg"
isChecked={isChecked}
onChange={handleChange}
/>
<p className="ml-2">Ubah ke akun bisnis</p>
</div>
))}
{isChecked && ubahAkun !== 'pending' && (
<div>
<SwitchAccount company_type="nonpkp" setIsAprove={setIsAprove} setUbahAkun={setUbahAkun}/>
<Divider />
</div>
)}
{/* {!auth?.parentId
? auth?.parentId
: auth?.parent_id &&
isAprove != 'unknown' && (
<StatusSwitchAccount status={isAprove} />
)} */}
<PersonalProfile />
<Divider />
{(auth?.parentId || auth?.company) && <CompanyProfile />}
</AppLayout>
</MobileView>
<DesktopView>
<BasicLayout>
<div className="container mx-auto flex py-10">
<div className="w-3/12 pr-4">
<Menu />
</div>
<div className="w-9/12 bg-white border border-gray_r-6 rounded">
{auth?.company || ((isChecked || (!ubahAkun && ubahAkun !== 'pending')) && (
<div className="text-sm p-4 flex items-center">
<Checkbox
borderColor="gray.600"
colorScheme="red"
size="lg"
isChecked={isChecked}
onChange={handleChange}
/>
<p className="ml-2">Ubah ke akun bisnis</p>
</div>
))}
{isChecked && ubahAkun !== 'pending' && (
<div>
<SwitchAccount company_type="nonpkp" setIsAprove={setIsAprove} setUbahAkun={setUbahAkun}/>
<Divider />
</div>
)}
{/* {!auth?.parentId
? auth?.parentId
: auth?.parent_id &&
isAprove != 'unknown' && (
<StatusSwitchAccount status={isAprove} />
)} */}
<PersonalProfile />
<Divider />
{(auth?.parentId || auth?.company) && <CompanyProfile />}
</div>
</div>
</BasicLayout>
</DesktopView>
</IsAuth>
</>
);
}
|