Skip to content

Commit 2a6046b

Browse files
committed
2 parents 82968dc + b3b586e commit 2a6046b

File tree

11 files changed

+132
-30
lines changed

11 files changed

+132
-30
lines changed

src/app/App.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Backdrop, Box, CircularProgress, createStyles, Grid, Theme } from "@material-ui/core"
1+
import { Backdrop, Box, CircularProgress, createStyles, Grid, Snackbar, Theme } from "@material-ui/core"
22
import Container from '@material-ui/core/Container'
33
import { makeStyles } from "@material-ui/core/styles"
44
import { AuthRoute } from 'app/AuthRoute'
@@ -30,6 +30,7 @@ import CheckInPointForm from "features/SalesAndOrganisation/CheckInPointForm"
3030
import { fetchVisitorConfigs } from "features/Settings/visitorConfigSlice"
3131
import ContractorView from "features/contractor/contractorView"
3232
import EmployeeForm from "features/Employees/EmployeeForm"
33+
import { startSnackbar, stopSnackbar } from "./SnackbarSlice"
3334

3435

3536
const useStyles = makeStyles((theme: Theme) =>
@@ -69,6 +70,7 @@ export default function App() {
6970

7071
const { isLoggedIn } = useSelector((state: RootState) => state.auth)
7172
const { mask } = useSelector((state: RootState) => state.backdrop)
73+
const { open, vertical, horizontal, message } = useSelector((state: RootState) => state.snackbar)
7274

7375
if (!isLoggedIn) {
7476
// debugger
@@ -88,6 +90,14 @@ export default function App() {
8890
<Backdrop className={classes.backdrop} open={mask}>
8991
<CircularProgress color="inherit" />
9092
</Backdrop>
93+
<Snackbar
94+
anchorOrigin={{ vertical: "bottom", horizontal: "center" }}
95+
open={open}
96+
autoHideDuration={5000}
97+
onClose={() => dispatch(stopSnackbar())}
98+
message={message}
99+
key={vertical + horizontal}
100+
/>
91101
<Container maxWidth={"xl"} className={classes.root}>
92102
{/* <Grid container spacing={3} className={classes.fullHeightContainer}> */}
93103
{/* <Grid item> */}

src/app/SnackbarSlice.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { createSlice, PayloadAction } from '@reduxjs/toolkit';
2+
3+
interface SnackbarState {
4+
open: boolean,
5+
message: string,
6+
vertical: string,
7+
horizontal: string,
8+
}
9+
10+
const snackbarInitialState: SnackbarState = {
11+
open: false,
12+
message: '',
13+
vertical: 'bottom',
14+
horizontal: 'center',
15+
}
16+
17+
const SnackbarSlice = createSlice({
18+
name: 'snackbar',
19+
initialState: snackbarInitialState,
20+
reducers: {
21+
startSnackbar(state: SnackbarState, { payload }: PayloadAction<any>) {
22+
const {message} = payload
23+
state.open = true
24+
state.message = message
25+
},
26+
stopSnackbar(state: SnackbarState) {
27+
state.open = false
28+
}
29+
}
30+
})
31+
32+
export const {
33+
startSnackbar,
34+
stopSnackbar
35+
} = SnackbarSlice.actions
36+
37+
export default SnackbarSlice.reducer

src/app/rootReducer.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { combineReducers } from '@reduxjs/toolkit'
33

44
import homeReducer from 'features/Home/homeSlice'
55
import backDropReducer from 'app/BackdropSlice'
6+
import snackBarReducer from 'app/SnackbarSlice'
67
import visitorReducer from 'features/Home/visitorSlice'
78
import inviteReducer from 'features/Invites/inviteSlice'
89
import employeeReducer from 'features/Employees/employeeSlice'
@@ -17,6 +18,7 @@ import contractorReducer from 'features/contractor/contractorSlice'
1718

1819
const rootReducer = combineReducers({
1920
backdrop: backDropReducer,
21+
snackbar: snackBarReducer,
2022
home: homeReducer,
2123
visitors: visitorReducer,
2224
invites: inviteReducer,

src/features/Employees/employeeSlice.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Links } from 'parse-link-header'
44
import { createEmployee, getEmployeesData } from 'api/Apis'
55
import { AppThunk } from 'app/store'
66
import { getBackdropStart, getBackdropStop } from 'app/BackdropSlice'
7+
import { startSnackbar } from 'app/SnackbarSlice'
78

89
export interface Employee {
910
createdOn: any,//2020-09-30 13: 14: 38,
@@ -127,12 +128,20 @@ export const saveEmployee = (
127128
try {
128129
dispatch(getBackdropStart())
129130
await createEmployee(employeeFormData)
130-
.then(() => dispatch(getBackdropStop())).catch(() => dispatch(getBackdropStop()))
131+
.then(() => {
132+
dispatch(getBackdropStop())
133+
dispatch(startSnackbar({ message: 'Employee created' }))
134+
})
135+
.catch(() => {
136+
dispatch(getBackdropStop())
137+
dispatch(startSnackbar({ message: 'Something went wrong' }))
138+
})
131139
//return setInputState(defaultInputState)
132140
callback && callback();
133141
//dispatch(saveInvitesSuccess(invites))
134142
} catch (err) {
135143
dispatch(getBackdropStop())
144+
dispatch(startSnackbar({ message: 'Something went wrong' }))
136145
}
137146
}
138147

src/features/Home/VisitorDetailsView1.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { fetchVisitorConfigs } from "features/Settings/visitorConfigSlice";
1717
import img from 'assets/logo/logo.png'
1818
import { fetchSites } from "features/SalesAndOrganisation/siteSlice";
1919
import { fetchEmployees } from "features/Employees/employeeSlice";
20+
import { startSnackbar } from "app/SnackbarSlice";
2021

2122
const useStyles = makeStyles((theme: Theme) => createStyles({
2223
paper: {
@@ -228,7 +229,13 @@ const VisitorDetailsView: FunctionComponent<Props> = (props) => {
228229
"Content-Length": 2617
229230
},
230231
})
231-
.then(() => dispatch(getBackdropStop())).catch(() => dispatch(getBackdropStop()))
232+
.then(() => {
233+
dispatch(getBackdropStop())
234+
dispatch(startSnackbar({message: 'Visitor checked in'}))
235+
}).catch(() => {
236+
dispatch(getBackdropStop())
237+
dispatch(startSnackbar({ message: 'Something went wrong'}))
238+
})
232239
}
233240

234241
const handlePurpose = (value: any) => {

src/features/Invites/inviteSlice.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { AppThunk } from 'app/store'
66
import {getBackdropStart, getBackdropStop} from 'app/BackdropSlice'
77
import { fetchSites } from 'features/SalesAndOrganisation/siteSlice'
88
import { getPurposeSuccess } from 'features/Home/visitorSlice'
9+
import { startSnackbar } from 'app/SnackbarSlice'
910

1011

1112
export interface Invite {
@@ -108,13 +109,21 @@ export const saveInvite = (
108109
//dispatch(saveInviteStart())
109110
dispatch(getBackdropStart())
110111
await createInvite(invite)
111-
.then(() => dispatch(getBackdropStop())).catch(() => dispatch(getBackdropStop()))
112+
.then(() => {
113+
dispatch(getBackdropStop())
114+
dispatch(startSnackbar({message: 'Your invitee has been invited'}))
115+
})
116+
.catch(() => {
117+
dispatch(getBackdropStop())
118+
dispatch(startSnackbar({ message: 'Something went wrong' }))
119+
})
112120
//return setInputState(defaultInputState)
113121
callback && callback();
114122
//dispatch(saveInvitesSuccess(invites))
115123
} catch (err) {
116124
//dispatch(saveInvitesFailure(err.toString()))
117125
dispatch(getBackdropStop())
126+
dispatch(startSnackbar({ message: 'Something went wrong' }))
118127
}
119128
}
120129

@@ -128,7 +137,7 @@ export const fetchInOfficeInvites = (
128137
dispatch(getInvitesStart())
129138
const visitors = await getInOfficeInviteData()
130139
dispatch(getInvitesSuccess(visitors))
131-
140+
132141
const purpose = await getPurpose()
133142
dispatch(getPurposeSuccess(purpose))
134143
} catch (err) {

src/features/SalesAndOrganisation/SitesView.tsx

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -77,21 +77,21 @@ const SitesView: FunctionComponent<Props> = (props) => {
7777
dispatch(fetchSites(page, count))
7878
},
7979
totalCount: pageCount,
80-
menuOptions: [{
81-
item: (id: any) => <CustomMenuItem to='/' onClick={() => console.log('check out ' + id)}>
82-
Delete
83-
</CustomMenuItem>
84-
},
85-
{
86-
item: (id: any) => <CustomMenuItem to='/' onClick={() => console.log('check out ' + id)}>
87-
Disable
88-
</CustomMenuItem>
89-
},
90-
{
91-
item: (id: any) => <CustomMenuItem to='/' onClick={() => console.log('check out ' + id)}>
92-
View Details
93-
</CustomMenuItem>
94-
}]
80+
// menuOptions: [{
81+
// item: (id: any) => <CustomMenuItem to='/' onClick={() => console.log('check out ' + id)}>
82+
// Delete
83+
// </CustomMenuItem>
84+
// },
85+
// {
86+
// item: (id: any) => <CustomMenuItem to='/' onClick={() => console.log('check out ' + id)}>
87+
// Disable
88+
// </CustomMenuItem>
89+
// },
90+
// {
91+
// item: (id: any) => <CustomMenuItem to='/' onClick={() => console.log('check out ' + id)}>
92+
// View Details
93+
// </CustomMenuItem>
94+
// }]
9595
}
9696

9797
useEffect(() => {
@@ -102,7 +102,8 @@ const SitesView: FunctionComponent<Props> = (props) => {
102102
<Grid item xs={12} style={{ marginRight: '30px' }}>
103103
<Paper className={classes.paper}>
104104
<Box display="flex" justifyContent="space-between" style={{ paddingTop: '38px', paddingBottom: '26px' }}>
105-
<SearchInput placeholder="Search Employees by name, email or mobile" width={354} style={{ paddingLeft: '30px' }} />
105+
<SearchInput hidden placeholder="Search Site by name" width={354} style={{ paddingLeft: '30px' }} />
106+
<div style={{width:353}}/>
106107
{/* <SelectInput value="Action" menuOptions={selectInputMenu} style={{ width: '122px' }} /> */}
107108
<CustomMenuItem to='/sites/add'>
108109
<CustomButton style={{ width: '122px', fontSize: '12px', height: '39px', padding: 0 }}>

src/features/SalesAndOrganisation/checkInPointSlice.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Links } from 'parse-link-header'
44
import { createCheckInPoint, getCheckInPointsData } from 'api/Apis'
55
import { AppThunk } from 'app/store'
66
import { getBackdropStart, getBackdropStop } from 'app/BackdropSlice'
7+
import { startSnackbar } from 'app/SnackbarSlice'
78

89

910
export interface CheckInPoint {
@@ -112,11 +113,19 @@ export const saveCheckInPoint = (
112113
try {
113114
dispatch(getBackdropStart())
114115
await createCheckInPoint(site)
115-
.then(() => dispatch(getBackdropStop())).catch(() => dispatch(getBackdropStop()))
116+
.then(() => {
117+
dispatch(getBackdropStop())
118+
dispatch(startSnackbar({ message: 'Check In Point created' }))
119+
})
120+
.catch(() => {
121+
dispatch(getBackdropStop())
122+
dispatch(startSnackbar({ message: 'Something went wrong' }))
123+
})
116124
//return setInputState(defaultInputState)
117125
callback && callback();
118126
//dispatch(saveInvitesSuccess(invites))
119127
} catch (err) {
120128
dispatch(getBackdropStop())
129+
dispatch(startSnackbar({ message: 'Something went wrong' }))
121130
}
122131
}

src/features/SalesAndOrganisation/siteSlice.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Links } from 'parse-link-header'
44
import { createSite, getSitesData } from 'api/Apis'
55
import { AppThunk } from 'app/store'
66
import { getBackdropStart, getBackdropStop } from 'app/BackdropSlice'
7+
import { startSnackbar } from 'app/SnackbarSlice'
78

89

910
export interface Site {
@@ -113,12 +114,20 @@ export const saveSite = (
113114
try {
114115
dispatch(getBackdropStart())
115116
await createSite(site)
116-
.then(() => dispatch(getBackdropStop())).catch(() => dispatch(getBackdropStop()))
117+
.then(() => {
118+
dispatch(getBackdropStop())
119+
dispatch(startSnackbar({ message: 'Site created' }))
120+
})
121+
.catch(() => {
122+
dispatch(getBackdropStop())
123+
dispatch(startSnackbar({ message: 'Something went wrong' }))
124+
})
117125
//return setInputState(defaultInputState)
118126
callback && callback();
119127
//dispatch(saveInvitesSuccess(invites))
120128
} catch (err) {
121129
dispatch(getBackdropStop())
130+
dispatch(startSnackbar({ message: 'Something went wrong' }))
122131
}
123132
}
124133

src/features/Settings/DevicesView.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ const DevicesView: FunctionComponent<Props> = (props) => {
115115
<Grid item xs style={{ height: "100%" }}>
116116
<Paper className={classes.paper}>
117117
<Box display="flex" justifyContent="space-between" style={{ paddingTop: '37.5px', paddingBottom: '24px' }}>
118-
<SearchInput style={{ marginLeft: '28.5px', height: '39px' }} placeholder="Search Devices" width={400} />
118+
<SearchInput hidden style={{ marginLeft: '28.5px', height: '39px' }} placeholder="Search Devices" width={400} />
119+
<div style={{width:353}}/>
119120
<Box display="flex">
120121
{/* <SelectInput style={{ marginRight: '26px', width: '122px', height: '39px' }} value = {""} defaultValue="All Sites" menuOptions={[]} /> */}
121122
{/* <SelectInput style={{ marginRight: '26px', width: '122px', height: '39px' }} value = {""} defaultValue="All Status" menuOptions={[]} /> */}

src/features/Settings/deviceSlice.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Links } from 'parse-link-header'
44
import { createDevice, getDevicesData } from 'api/Apis'
55
import { AppThunk } from 'app/store'
66
import { getBackdropStart, getBackdropStop } from 'app/BackdropSlice'
7+
import { startSnackbar } from 'app/SnackbarSlice'
78

89

910
export interface Device {
@@ -104,11 +105,18 @@ export const saveDevice = (
104105
try {
105106
dispatch(getBackdropStart())
106107
await createDevice(device)
107-
.then(() => dispatch(getBackdropStop())).catch(() => dispatch(getBackdropStop()))
108-
//return setInputState(defaultInputState)
109-
callback && callback();
110-
//dispatch(saveInvitesSuccess(invites))
111-
} catch (err) {
112-
dispatch(getBackdropStop())
108+
.then(() => {
109+
dispatch(getBackdropStop())
110+
dispatch(startSnackbar({message: 'Device created'}))
111+
}).catch(() => {
112+
dispatch(getBackdropStop())
113+
dispatch(startSnackbar({ message: 'Something went wrong'}))
114+
})
115+
//return setInputState(defaultInputState)
116+
callback && callback();
117+
//dispatch(saveInvitesSuccess(invites))
118+
} catch (err) {
119+
dispatch(getBackdropStop())
120+
dispatch(startSnackbar({ message: 'Something went wrong'}))
113121
}
114122
}

0 commit comments

Comments
 (0)