Skip to content

Commit

Permalink
Merge pull request #78 from NicolasMarqui/getStartedPage
Browse files Browse the repository at this point in the history
UI Changes - Get Started page
  • Loading branch information
saul-data authored Jan 19, 2022
2 parents 0243734 + 851f9d7 commit 8393f8e
Show file tree
Hide file tree
Showing 5 changed files with 248 additions and 234 deletions.
1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10",
"axios": "^0.24.0",
"check-password-strength": "^2.0.3",
"countries-and-timezones": "^3.3.0",
"env-cmd": "^10.1.0",
"graphql": "^16.1.0",
Expand Down
49 changes: 33 additions & 16 deletions frontend/src/components/GetStartedForm/index.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { Box, Button, Grid, TextField, Typography } from '@mui/material';
import { Autocomplete, Box, Button, TextField, Typography } from '@mui/material';
import { useForm } from 'react-hook-form';
import { useCreateAdmin } from '../../graphql/createAdmin';
import CustomSwitch from '../CustomSwitch';
import { useSnackbar } from 'notistack';
import ct from 'countries-and-timezones';
import ThemeToggle from '../ThemeToggle';
import PasswordField from '../PasswordField';

const GetStartedForm = ({ handleNext }) => {
const createAdmin = useCreateAdmin();
Expand All @@ -14,12 +16,10 @@ const GetStartedForm = ({ handleNext }) => {
} = useForm();

async function onSubmit(data) {
console.log(data);

const allData = {
platform: {
business_name: data.business_name,
timezone: 'GMT+2',
timezone: data.timezone,
complete: false,
},
users: {
Expand All @@ -28,7 +28,7 @@ const GetStartedForm = ({ handleNext }) => {
email: data.email,
job_title: data.job_title,
password: data.password,
timezone: 'GMT+3',
timezone: data.timezone,
},
};

Expand All @@ -44,7 +44,7 @@ const GetStartedForm = ({ handleNext }) => {
}

return (
<form onSubmit={handleSubmit(onSubmit)}>
<Box component="form" sx={{ width: { sm: '250px' } }} onSubmit={handleSubmit(onSubmit)}>
<Box sx={{ mt: 3, mb: 3 }} display="block">
<Typography component="h3" variant="h2" color="text.primary">
Business
Expand All @@ -58,6 +58,22 @@ const GetStartedForm = ({ handleNext }) => {
{...register('business_name', { required: true })}
/>

<Autocomplete
disablePortal
id="combo-box-demo"
options={Object.keys(ct.getAllTimezones())}
renderInput={(params) => (
<TextField
{...params}
label="Timezone"
id="timezone"
size="small"
sx={{ mt: 2, fontSize: '.75rem', display: 'flex' }}
{...register('timezone', { required: true })}
/>
)}
/>

{errors.businessName && (
<Typography variant="subtitle1" color="danger" mt={1}>
This field is required
Expand Down Expand Up @@ -102,33 +118,34 @@ const GetStartedForm = ({ handleNext }) => {
sx={{ mb: 2, fontSize: '.75rem', display: 'flex' }}
{...register('job_title', { required: true })}
/>
<TextField
<PasswordField
label="Password"
id="password"
name="password"
type="password"
size="small"
required
sx={{ fontSize: '.75rem', display: 'flex' }}
{...register('password', { required: true })}
style={{ fontSize: '.75rem', display: 'flex' }}
register={{ ...register('password', { required: true }) }}
/>
</Box>

<Grid container alignItems="center" justifyContent="center">
<CustomSwitch />
<Typography ml="1.5rem" variant="subtitle2" color="text.primary" fontSize={14}>
<Box display="flex" alignItems="center" justifyContent="space-evenly">
<ThemeToggle />
<Typography color="text.primary" fontSize={14} lineHeight="16.41px">
Mode{' '}
<Typography display="block" variant="subtitle2" fontSize={14}>
<Typography component="span" display="block" fontSize={14}>
preference
</Typography>
</Typography>
</Grid>
</Box>

<Box sx={{ mt: '37px' }}>
<Button variant="contained" type="submit" color="primary" sx={{ width: '100%' }}>
Next
</Button>
</Box>
</form>
</Box>
);
};

Expand Down
160 changes: 80 additions & 80 deletions frontend/src/components/PasswordField/index.jsx
Original file line number Diff line number Diff line change
@@ -1,93 +1,93 @@
import React, { useEffect } from "react";
import { GushTextfield } from "@gushai-platform/gush-svc-react-ui-lib/dist";
import "./passwordField.scss";
import InputAdornment from "@material-ui/core/InputAdornment";
import { useState } from "@hookstate/core";
import { passwordStrength } from "check-password-strength";
import React, { useEffect } from 'react';
import './passwordField.css';
import { useState } from '@hookstate/core';
import { passwordStrength } from 'check-password-strength';
import { InputAdornment, TextField } from '@mui/material';

const PasswordReturn = (score) => {
switch (score) {
case "Too weak":
return [1, "weak"];
case "Weak":
return [2, "weak"];
case "Medium":
return [3, "medium"];
case "Strong":
return [4, "strong"];
default:
return [1, "weak"];
}
switch (score) {
case 'Too weak':
return [1, 'weak'];
case 'Weak':
return [2, 'weak'];
case 'Medium':
return [3, 'medium'];
case 'Strong':
return [4, 'strong'];
default:
return [1, 'weak'];
}
};

const PasswordField = (props) => {
const password = useState("");
const strength = useState(0);
const showInfo = useState(false);
const password = useState('');
const strength = useState(0);
const showInfo = useState(false);

/* https://github.com/mui-org/material-ui/pull/21984 */
useEffect(() => {
document.body.style.overflowX = "hidden";
return () => {
document.body.style.overflowX = "";
};
}, []);
/* https://github.com/mui-org/material-ui/pull/21984 */
useEffect(() => {
document.body.style.overflowX = 'hidden';
return () => {
document.body.style.overflowX = '';
};
}, []);

const minStrength = 3;
const thresholdLength = 6;
const passwordLength = password.get().length;
const isPasswordStrong = strength.get() >= minStrength;
const isPasswordLong = passwordLength > thresholdLength;
const minStrength = 3;
const thresholdLength = 6;
const passwordLength = password.get().length;
const isPasswordStrong = strength.get() >= minStrength;
const isPasswordLong = passwordLength > thresholdLength;

console.log(strength.get());
console.log(strength.get());

const strengthClass = ["strength-meter mt-2", passwordLength > 0 ? "visible" : "invisible"].join(" ").trim();
const counterClass = ["badge badge-pill", isPasswordLong ? (isPasswordStrong ? "badge-success" : "badge-warning") : "badge-danger"]
.join(" ")
.trim();
return (
<div className="position-relative">
<GushTextfield
type="password"
valid={isPasswordLong}
{...props}
InputProps={{
endAdornment: (
<InputAdornment position="end">
{password.get() !== "" && <span className={counterClass}>{PasswordReturn(passwordStrength(password.get()).value)[1]}</span>}
</InputAdornment>
),
}}
onChange={(e) => {
const newPassword = e.target.value;
console.log("password strength", PasswordReturn(passwordStrength(newPassword).value));
password.set(newPassword);
strength.set(PasswordReturn(passwordStrength(newPassword).value)[0]);
}}
onFocus={(e) => {
showInfo.set(true);
}}
onBlur={() => {
if (passwordLength === 0) {
showInfo.set(false);
}
}}
/>
const strengthClass = ['strength-meter mt-2', passwordLength > 0 ? 'visible' : 'invisible'].join(' ').trim();
const counterClass = ['badge badge-pill', isPasswordLong ? (isPasswordStrong ? 'badge-success' : 'badge-warning') : 'badge-danger'].join(' ').trim();
return (
<div className="position-relative">
<TextField
type="password"
valid={isPasswordLong.toString()}
{...props}
InputProps={{
endAdornment: (
<InputAdornment position="end">
{password.get() !== '' && <span className={counterClass}>{PasswordReturn(passwordStrength(password.get()).value)[1]}</span>}
</InputAdornment>
),
}}
ref={props.register.ref}
onChange={(e) => {
props.register.onChange(e);
const newPassword = e.target.value;
console.log('password strength', PasswordReturn(passwordStrength(newPassword).value));
password.set(newPassword);
strength.set(PasswordReturn(passwordStrength(newPassword).value)[0]);
}}
onFocus={(e) => {
showInfo.set(true);
}}
onBlur={() => {
if (passwordLength === 0) {
showInfo.set(false);
strength.set(0);
}
}}
/>

{showInfo.get() ? (
<div>
<div className="password-message">
{!isPasswordLong && <div className="password-red"> Password strength</div>}
{isPasswordLong && !isPasswordStrong && <div className="password-orange"> Password strength</div>}
{isPasswordLong && isPasswordStrong && <div className="password-green"> Password strength</div>}
</div>
<div className={strengthClass}>
<div className="strength-meter-fill" data-strength={strength.get()}></div>
</div>
{showInfo.get() ? (
<div>
<div className="password-message">
{!isPasswordLong && <div className="password-red"> Password strength</div>}
{isPasswordLong && !isPasswordStrong && <div className="password-orange"> Password strength</div>}
{isPasswordLong && isPasswordStrong && <div className="password-green"> Password strength</div>}
</div>
<div className={strengthClass}>
<div className="strength-meter-fill" data-strength={strength.get()}></div>
</div>
</div>
) : null}
</div>
) : null}
</div>
);
);
};

export default PasswordField;
export default PasswordField;
Loading

0 comments on commit 8393f8e

Please sign in to comment.