-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathindex.jsx
223 lines (208 loc) · 8.32 KB
/
index.jsx
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
import withAuth from '@/core/utils/protectedRoute';
import React, { useState, useEffect } from 'react';
import Layout from '@/components/Layout';
import CheckIcon from '@/icons/tickIcon';
import Link from 'next/link';
import Button from '@/components/Button';
import Image from 'next/image';
import AnalyticsImage from '@/images/Home/analyticsImage.png';
import PlayIcon from '@/images/Home/playIcon.svg';
import AnalyticsVideo from '../../../public/videos/analytics.mp4';
import { useSelector, useDispatch } from 'react-redux';
import { startTask, completeTask, updateTitle } from '@/lib/store/services/checklists/CheckList';
import HomeSkeleton from '@/components/skeletons/HomeSkeleton';
import CustomModal from '@/components/Modal/videoModals/CustomModal';
import StepProgress from '@/components/steppers/CircularStepper';
const Home = () => {
const dispatch = useDispatch();
const checkListData = useSelector((state) => state.checklists.checklist);
const cardCheckList = useSelector((state) => state.cardChecklist.cards);
const userData = JSON.parse(localStorage.getItem('loggedUser'));
const checkListStatus = useSelector((state) => state.checklists.status);
const [open, setOpen] = useState(false);
const [step, setStep] = useState(0);
const totalSteps = 4;
useEffect(() => {
const completedCards = cardCheckList.filter((card) => card.completed === true);
setStep(completedCards.length);
}, [cardCheckList]);
const handleModel = () => {
setOpen(!open);
const card = cardCheckList.find((card) => card.id === 1);
if (card) {
switch (card.status) {
case 'not started':
dispatch(startTask(1));
dispatch(updateTitle({ id: 1, title: 'analytics_video' }));
break;
default:
return;
}
} else {
console.log('Card not found');
}
};
const handleCardClick = (id) => {
if (id === 4) {
dispatch(completeTask(4));
} else {
const card = cardCheckList.find((card) => card.id === id);
if (card) {
switch (card.status) {
case 'not started':
dispatch(startTask(id));
break;
default:
return;
}
} else {
console.log('Card not found');
}
}
};
const steps = [
{
label: 'Introduction AirQo Analytics demo video',
time: '1 min',
link: '#',
func: () => handleModel(),
},
{
label: 'Choose location you most interested in',
time: '2 min',
link: '/analytics',
func: () => handleCardClick(2),
},
{
label: 'Complete your AirQo Analytics profile',
time: '4 min',
link: '/settings',
func: () => handleCardClick(3),
},
{
label: 'Practical ways to reduce air pollution',
time: '1 min',
link: 'https://blog.airqo.net/',
func: () => handleCardClick(4),
},
];
return (
<Layout noBorderBottom pageTitle='Home'>
{checkListStatus === 'loading' && checkListData.length === 0 ? (
<HomeSkeleton />
) : (
<>
<div className='px-3 lg:px-16 py-3 space-y-5'>
<div className='w-full mb-4 md:mb-10'>
<h1 className='text-[32px] leading-10 font-medium'>
Welcome, <span className='capitalize'>{userData?.firstName}</span> 👋
</h1>
</div>
<div className='w-full flex justify-between items-center'>
<div className='w-full flex flex-col items-start'>
<h1 className='text-2xl font-medium text-gray-900'>Onboarding checklist</h1>
<p className='text-sm font-normal text-gray-500'>
We recommend starting with our onboarding checklist.
</p>
</div>
<div className='w-full'>
<StepProgress step={step} totalSteps={totalSteps} />
</div>
</div>
<div className='w-full grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-5'>
{steps.map((step, index) => {
const card = cardCheckList.find((card) => card.id === index + 1);
const statusText = card && card.completed === true ? 'Done' : 'Start';
const statusColor =
card && card.completed === true ? 'text-black' : 'text-blue-600';
const justifyStyle =
card && card.completed === true ? 'justify-end' : 'justify-between';
return (
<div
key={index}
className='w-full h-[250px] flex flex-col justify-between items-start border-[0.5px] rounded-xl border-grey-150 py-5 px-3 space-y-5 focus:outline-blue-600 focus:ring-2 focus:shadow-lg focus:border-blue-600'
tabIndex={0}>
<div className='w-full'>
{card && card.completed === true ? (
<div className='w-14 h-14 flex justify-center items-center rounded-full bg-blue-900'>
<CheckIcon fill='#FFFFFF' />
</div>
) : (
<div
className='text-base w-14 h-14 flex justify-center items-center font-medium rounded-full'
style={{ background: '#F5F5FF' }}>
<span className='text-blue-600'>{index + 1}</span>
</div>
)}
</div>
<p className='w-full text-base font-normal'>{step.label}</p>
<div className={`w-full text-sm flex ${justifyStyle} font-normal`}>
{card && card.completed === true ? (
<span className={statusColor}>{statusText}</span>
) : (
<>
<Link href={step.link}>
<a
onClick={step.func}
className={statusColor}
target={index === 3 ? '_blank' : ''}>
{card && card.status === 'inProgress' ? 'Resume' : statusText}
</a>
</Link>
<span className='text-sm font-normal text-black-900'>{step.time}</span>
</>
)}
</div>
</div>
);
})}
</div>
<div className='w-full grid grid-cols-1 md:grid-cols-2 gap-3 items-center border-[0.5px] rounded-xl border-grey-150 p-3'>
<div className='flex flex-col justify-start p-8'>
<h1 className='text-black-900 text-2xl font-medium'>
Track air pollution in places you care about
</h1>
<p className='text-lg font-normal text-black-900 mt-2'>
Empower yourself with knowledge about the air you breathe; because clean air
begins with understanding
</p>
<div className='mt-4 flex items-center space-x-8'>
<Button
path='/analytics'
className='bg-blue-900 text-white rounded-lg w-32 h-12'
dataTestId='get-started-button'>
Start here
</Button>
<a
onClick={handleModel}
className='text-blue-600 text-sm font-normal mt-2 cursor-pointer hidden'>
Show me how
</a>
</div>
</div>
<div
className='rounded-md p-9 relative'
style={{
background: '#145DFF08',
}}>
<div
onClick={handleModel}
className='absolute z-50 inset-0 flex items-center justify-center cursor-pointer hidden'>
<PlayIcon />
</div>
<Image src={AnalyticsImage} alt='Analytics Image' width={600} height={350} />
</div>
</div>
</div>
<CustomModal
open={open}
setOpen={setOpen}
videoUrl={AnalyticsVideo}
checklistData={cardCheckList}
/>
</>
)}
</Layout>
);
};
export default withAuth(Home);