authscape 1.0.632 → 1.0.636

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.
@@ -0,0 +1,404 @@
1
+ import React, {useEffect, useRef, useState} from 'react';
2
+ import { Box } from '@mui/system';
3
+ import Grid from '@mui/material/Grid';
4
+ import Button from '@mui/material/Button';
5
+ import { styled } from '@mui/material/styles';
6
+ import Dialog from '@mui/material/Dialog';
7
+ import DialogTitle from '@mui/material/DialogTitle';
8
+ import DialogContent from '@mui/material/DialogContent';
9
+ import DialogActions from '@mui/material/DialogActions';
10
+ import IconButton from '@mui/material/IconButton';
11
+ import CloseIcon from '@mui/icons-material/Close';
12
+ import Typography from '@mui/material/Typography';
13
+ import Stepper from '@mui/material/Stepper';
14
+ import Step from '@mui/material/Step';
15
+ import StepLabel from '@mui/material/StepLabel';
16
+ import TextField from '@mui/material/TextField';
17
+ import FmdBadRoundedIcon from '@mui/icons-material/FmdBadRounded';
18
+ import FormControl from '@mui/material/FormControl';
19
+ import Select from '@mui/material/Select';
20
+ import MenuItem from '@mui/material/MenuItem';
21
+ import ContentCopyRoundedIcon from '@mui/icons-material/ContentCopyRounded';
22
+ // import { apiService } from 'authscape';
23
+ import CircularProgress from '@mui/material/CircularProgress';
24
+ import { DialogContentText } from '@mui/material';
25
+
26
+ export function AddDomain({open, azureWebsite, azureTxtValue, handleClose}) {
27
+
28
+ const steps = ['Enter a domain', 'Setup DNS Record', 'Go Live'];
29
+
30
+ const [activeStep, setActiveStep] = useState(0);
31
+ const [completed, setCompleted] = useState({});
32
+
33
+ // const [domain, setDomain] = useState(null);
34
+ const [subDomains, setSubDomains] = useState(null);
35
+ // const [topLevelDomains , setTopLevelDomains ] = useState(null);
36
+
37
+ const [fullDomain, setFullDomain] = useState(null);
38
+ const [errorMessage, setErrorMessage] = useState(null);
39
+
40
+ const refDomain = useRef(null);
41
+
42
+ const refCNameTarget = useRef(null);
43
+ const reftxtTarget = useRef(null);
44
+
45
+ const refCNameName = useRef(null);
46
+ const reftxtName = useRef(null);
47
+
48
+ const totalSteps = () => {
49
+ return steps.length;
50
+ };
51
+
52
+ const completedSteps = () => {
53
+ return Object.keys(completed).length;
54
+ };
55
+
56
+ const isLastStep = () => {
57
+ return activeStep === totalSteps() - 1;
58
+ };
59
+
60
+ const allStepsCompleted = () => {
61
+ return completedSteps() === totalSteps();
62
+ };
63
+
64
+ const handleNext = () => {
65
+ const newActiveStep =
66
+ isLastStep() && !allStepsCompleted()
67
+ ? // It's the last step, but not all steps have been completed,
68
+ // find the first step that has been completed
69
+ steps.findIndex((step, i) => !(i in completed))
70
+ : activeStep + 1;
71
+ setActiveStep(newActiveStep);
72
+ };
73
+
74
+ const handleBack = () => {
75
+ setActiveStep((prevActiveStep) => prevActiveStep - 1);
76
+
77
+
78
+ };
79
+
80
+ const getSubdomain = (hostName) => {
81
+ const host = hostName; // e.g., subdomain.example.com
82
+ const parts = host.split('.');
83
+ if (parts.length > 2) {
84
+ return parts[0]; // This will be 'subdomain'
85
+ }
86
+ return null; // No subdomain found
87
+ };
88
+
89
+ const handleStep = (step) => () => {
90
+ setActiveStep(step);
91
+ };
92
+
93
+ const handleComplete = () => {
94
+ const newCompleted = completed;
95
+ newCompleted[activeStep] = true;
96
+ setCompleted(newCompleted);
97
+ handleNext();
98
+ };
99
+
100
+ const BootstrapDialog = styled(Dialog)(({ theme }) => ({
101
+ '& .MuiDialogContent-root': {
102
+ padding: theme.spacing(2),
103
+ },
104
+ '& .MuiDialogActions-root': {
105
+ padding: theme.spacing(1),
106
+ },
107
+ }));
108
+
109
+ const handleReset = () => {
110
+ setActiveStep(0);
111
+ setCompleted({});
112
+ };
113
+
114
+ const createTheDomainRequest = async () => {
115
+
116
+ if (fullDomain == null || fullDomain == "")
117
+ {
118
+ return;
119
+ }
120
+
121
+ let response = await apiService().post("/PrivateLabel/GenerateDomain", {
122
+ hostName: fullDomain
123
+ });
124
+
125
+ if (response != null && response.status == 200)
126
+ {
127
+ if (handleClose != null)
128
+ {
129
+ handleClose();
130
+ }
131
+ }
132
+ else
133
+ {
134
+ let aStep = activeStep - 1;
135
+ setActiveStep(aStep);
136
+ setErrorMessage(response.data);
137
+ }
138
+ }
139
+
140
+
141
+ useEffect(() => {
142
+
143
+ if (activeStep == 2)
144
+ {
145
+ createTheDomainRequest();
146
+ }
147
+
148
+ }, [activeStep]);
149
+
150
+
151
+ const copyToClipboard = async (text) => {
152
+ try {
153
+ const permissions = await navigator.permissions.query({name: "clipboard-write"})
154
+ if (permissions.state === "granted" || permissions.state === "prompt") {
155
+ await navigator.clipboard.writeText(text);
156
+ //alert('Copied to clipboard!');
157
+ } else {
158
+ throw new Error("Can't access the clipboard. Check your browser permissions.")
159
+ }
160
+ } catch (error) {
161
+ alert('Error copying to clipboard:', error);
162
+ }
163
+ };
164
+
165
+ function BootstrapDialogTitle(props) {
166
+ const { children, onClose, ...other } = props;
167
+
168
+ return (
169
+ <DialogTitle sx={{ m: 0, p: 2 }} {...other}>
170
+ {children}
171
+ {onClose ? (
172
+ <IconButton
173
+ aria-label="close"
174
+ onClick={onClose}
175
+ sx={{
176
+ position: 'absolute',
177
+ right: 8,
178
+ top: 8,
179
+ color: (theme) => theme.palette.grey[500],
180
+ }}
181
+ >
182
+ <CloseIcon />
183
+ </IconButton>
184
+ ) : null}
185
+ </DialogTitle>
186
+ );
187
+ }
188
+
189
+ return (
190
+ <BootstrapDialog onClose={handleClose} aria-labelledby="customized-dialog-title" sx={{backgroundColor: "rgba(0, 0, 0, 0.6)"}} fullWidth={true} maxWidth={"md"} open={open}>
191
+ <Box sx={{padding:4}}>
192
+
193
+ <Stepper activeStep={activeStep} alternativeLabel>
194
+ {steps.map((label) => (
195
+ <Step key={label}>
196
+ <StepLabel sx={{color:"#fff"}}>{label}</StepLabel>
197
+ </Step>
198
+ ))}
199
+ </Stepper>
200
+
201
+ {activeStep == 0 &&
202
+ <>
203
+ <BootstrapDialogTitle id="customized-dialog-title" onClose={handleClose} sx={{textAlign:"center", fontSize:30, marginTop:2, lineHeight: 1}}>
204
+ What domain would you like to connect to {process.env.companyName}?
205
+ </BootstrapDialogTitle>
206
+ <DialogContent>
207
+
208
+ <Box>
209
+ <TextField inputRef={refDomain} id="domainTxt" label="Enter subdomain URL e.g catalog.mydomain.com" fullWidth={true} variant="outlined" sx={{color:"white", marginTop:2 }} />
210
+ </Box>
211
+ <Box sx={{marginTop:2}}>
212
+ <Typography gutterBottom sx={{textAlign:"center", fontSize:14}}>
213
+ <FmdBadRoundedIcon sx={{color:"#1976d2", position:"relative", top:8}} /> You must own the domain and have the ability to add records
214
+ </Typography>
215
+ </Box>
216
+
217
+ </DialogContent>
218
+ <DialogActions>
219
+ <Button variant="contained" onClick={() => {
220
+
221
+ if (refDomain.current.value == "")
222
+ {
223
+ return;
224
+ }
225
+
226
+ setFullDomain(refDomain.current.value);
227
+
228
+
229
+
230
+
231
+ let _subDomain = getSubdomain(refDomain.current.value);
232
+ setSubDomains(_subDomain);
233
+
234
+ // var domainLand = parseDomain(refDomain.current.value);
235
+ // setDomain(domainLand.domain);
236
+ // setSubDomains(domainLand.subDomains);
237
+ // setTopLevelDomains(domainLand.topLevelDomains);
238
+
239
+ handleNext();
240
+ }}>
241
+ Next: Setup DNS
242
+ </Button>
243
+ </DialogActions>
244
+ </>
245
+ }
246
+
247
+
248
+
249
+
250
+ {activeStep == 1 &&
251
+ <>
252
+ <BootstrapDialogTitle id="customized-dialog-title" onClose={handleClose} sx={{textAlign:"center", fontSize:30, marginTop:2}}>
253
+ Configure your DNS
254
+ </BootstrapDialogTitle>
255
+ <DialogContent>
256
+
257
+ <Box>
258
+ <Typography gutterBottom sx={{textAlign:"center", fontSize:14}}>
259
+ Add a CNAME and TXT Record to your domain by visiting your DNS provider.
260
+ </Typography>
261
+ </Box>
262
+
263
+ <Box sx={{backgroundColor:"#f7f7f7", marginTop:5, paddingLeft:4, paddingRight:4}}>
264
+ <Grid container spacing={2} fullWidth={true} >
265
+ <Grid item xs={2}>
266
+ Type
267
+
268
+ <FormControl fullWidth sx={{paddingTop:2}}>
269
+ <Select
270
+ value={1} readOnly={true}>
271
+ <MenuItem value={1}>CNAME</MenuItem>
272
+ </Select>
273
+ </FormControl>
274
+
275
+ </Grid>
276
+ <Grid item xs={5}>
277
+ Name
278
+ <TextField inputRef={refCNameName} id="NameDomainTxt" label="" fullWidth={true} value={subDomains} variant="outlined" sx={{color:"white", paddingTop:2 }} />
279
+
280
+ <Box sx={{textAlign:"center", paddingTop:1}}>
281
+ <Button startIcon={<ContentCopyRoundedIcon/>} sx={{width:"100%"}} variant="contained" onClick={() => {
282
+ copyToClipboard(refCNameName.current.value);
283
+ }}>
284
+ Copy
285
+ </Button>
286
+ </Box>
287
+
288
+ </Grid>
289
+ <Grid item xs={5}>
290
+ Target
291
+ <TextField inputRef={refCNameTarget} id="targetDomainTxt" label="" fullWidth={true} value={azureWebsite} variant="outlined" sx={{color:"white", paddingTop:2 }} />
292
+
293
+ <Box sx={{textAlign:"center", paddingTop:1}}>
294
+ <Button startIcon={<ContentCopyRoundedIcon/>} sx={{width:"100%"}} variant="contained" onClick={() => {
295
+ copyToClipboard(refCNameTarget.current.value);
296
+ }}>
297
+ Copy
298
+ </Button>
299
+ </Box>
300
+
301
+ </Grid>
302
+ </Grid>
303
+ </Box>
304
+
305
+ <Box sx={{backgroundColor:"#f7f7f7", paddingLeft:4, paddingRight:4, marginTop:2, paddingBottom:4}}>
306
+ <Grid container spacing={2} fullWidth={true} >
307
+ <Grid item xs={2}>
308
+ Type
309
+
310
+ <FormControl fullWidth sx={{paddingTop:2}}>
311
+ <Select
312
+ value={1} readOnly={true}>
313
+ <MenuItem value={1}>TXT</MenuItem>
314
+ </Select>
315
+ </FormControl>
316
+
317
+ </Grid>
318
+ <Grid item xs={5}>
319
+ Name
320
+ <TextField inputRef={reftxtName} id="NameDomain2Txt" label="" fullWidth={true} value={"asuid." + subDomains} variant="outlined" sx={{color:"white", marginTop:2 }} />
321
+
322
+ <Box sx={{textAlign:"center", paddingTop:1}}>
323
+ <Button startIcon={<ContentCopyRoundedIcon/>} sx={{width:"100%"}} variant="contained" onClick={() => {
324
+ copyToClipboard(reftxtName.current.value);
325
+ }}>
326
+ Copy
327
+ </Button>
328
+ </Box>
329
+ </Grid>
330
+ <Grid item xs={5}>
331
+ Target
332
+ <TextField inputRef={reftxtTarget} id="targetDomain2Txt" label="" fullWidth={true} value={azureTxtValue} variant="outlined" sx={{color:"white", marginTop:2 }} />
333
+
334
+ <Box sx={{textAlign:"center", paddingTop:1}}>
335
+ <Button startIcon={<ContentCopyRoundedIcon/>} sx={{width:"100%"}} variant="contained" onClick={() => {
336
+ copyToClipboard(reftxtTarget.current.value);
337
+ }}>
338
+ Copy
339
+ </Button>
340
+ </Box>
341
+ </Grid>
342
+ </Grid>
343
+ </Box>
344
+
345
+
346
+ </DialogContent>
347
+ <DialogActions>
348
+ <Button variant="contained" onClick={() => {
349
+ handleNext();
350
+ }}>
351
+ Go Live
352
+ </Button>
353
+ </DialogActions>
354
+ </>
355
+ }
356
+
357
+ {activeStep == 2 &&
358
+ <Box>
359
+ <BootstrapDialogTitle id="customized-dialog-title" onClose={handleClose} sx={{textAlign:"center", fontSize:30, marginTop:4}}>
360
+ Creating your private label experience
361
+ </BootstrapDialogTitle>
362
+ <DialogContent>
363
+ <Box sx={{paddingTop:2, textAlign:"center"}}>
364
+ <Typography gutterBottom sx={{textAlign:"center", fontSize:18}}>
365
+ Please wait while we complete a few things on our side.
366
+ </Typography>
367
+ <Box sx={{paddingTop:2}}>
368
+ <CircularProgress color="inherit" />
369
+ </Box>
370
+ </Box>
371
+ </DialogContent>
372
+ </Box>
373
+ }
374
+
375
+ </Box>
376
+
377
+
378
+ <Dialog
379
+ open={errorMessage != null ? true : false}
380
+ onClose={() => {
381
+ setErrorMessage(null);
382
+ }}
383
+ aria-labelledby="alert-dialog-title"
384
+ aria-describedby="alert-dialog-description">
385
+ <DialogTitle id="alert-dialog-title">
386
+ {"Issue Detected"}
387
+ </DialogTitle>
388
+ <DialogContent>
389
+ <DialogContentText id="alert-dialog-description">
390
+ {errorMessage}
391
+ </DialogContentText>
392
+ </DialogContent>
393
+ <DialogActions>
394
+ <Button onClick={() => {
395
+ setErrorMessage(null);
396
+ }} autoFocus>
397
+ OK
398
+ </Button>
399
+ </DialogActions>
400
+ </Dialog>
401
+
402
+ </BootstrapDialog>
403
+ )
404
+ }