Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed the success toast to reflect Lazim's design #512

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion frontend/src/components/AuthManager/AuthManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import {
useGoogleLogin as googleAuth,
googleLogout,
TokenResponse,

Check warning on line 5 in frontend/src/components/AuthManager/AuthManager.tsx

View workflow job for this annotation

GitHub Actions / check

'TokenResponse' is defined but never used
} from '@react-oauth/google';
import {
useHistory,
Expand All @@ -15,7 +15,7 @@
import AuthContext from '../../context/auth';

import LandingPage from '../../pages/Landing/Landing';
import Home from '../../pages/Admin/Home';

Check warning on line 18 in frontend/src/components/AuthManager/AuthManager.tsx

View workflow job for this annotation

GitHub Actions / check

'Home' is defined but never used
import styles from './authmanager.module.css';
import { googleLogin } from '../../icons/other';
import SubscribeWrapper from './SubscrbeWrapper';
Expand Down Expand Up @@ -162,7 +162,7 @@
}
}

function createRefresh(userId: string, userType: string, token: string) {

Check warning on line 165 in frontend/src/components/AuthManager/AuthManager.tsx

View workflow job for this annotation

GitHub Actions / check

'token' is defined but never used
const endpoint =
userType === 'Admin' ? `/api/admins/${userId}` : `/api/riders/${userId}`;
return () => {
Expand Down Expand Up @@ -195,7 +195,7 @@
);

const SiteContent = () => {
const { visible, message, toastType } = useToast();
const { visible, message, toastType, setVisible } = useToast();
const localUserType = localStorage.getItem('userType');
return (
<>
Expand All @@ -204,6 +204,7 @@
<Toast
message={message}
toastType={toastType ? ToastStatus.SUCCESS : ToastStatus.ERROR}
onClose={() => setVisible(false)}
/>,
document.body
)}
Expand Down
29 changes: 24 additions & 5 deletions frontend/src/components/ConfirmationToast/ConfirmationToast.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,38 @@
import React from 'react';
import { check, block } from '../../icons/other/index';
import React, { useState } from 'react';

Check warning on line 1 in frontend/src/components/ConfirmationToast/ConfirmationToast.tsx

View workflow job for this annotation

GitHub Actions / check

'useState' is defined but never used
import { green_check, block, close } from '../../icons/other';
import styles from './confirmationtoast.module.css';
import { ToastStatus } from '../../context/toastContext';

type toastProps = {
message: string;
toastType?: ToastStatus;
onClose: () => void;
};

const Toast = ({ message, toastType }: toastProps) => {
const Toast = ({ message, toastType, onClose }: toastProps) => {
return typeof toastType === 'undefined' ||
toastType == ToastStatus.SUCCESS ? (
<div className={`${styles.toast} ${styles.successToast}`}>
<img alt="toast check" src={check} />
<p className={styles.toasttext}>{message}</p>
<button
onClick={() => {
namanhboi marked this conversation as resolved.
Show resolved Hide resolved
onClose();
}}
className={styles.closeButton}
>
<img src={close} className={styles.closeImg}></img>
</button>
<div className={styles.toastContent}>
<img alt="toast check" src={green_check} />
<p className={styles.toasttext}>{message}</p>
</div>
<button
onClick={() => {
namanhboi marked this conversation as resolved.
Show resolved Hide resolved
onClose();
}}
className={styles.continueButton}
>
<p className={styles.continueText}>Continue</p>
</button>
</div>
) : (
<div className={`${styles.toast} ${styles.errorToast}`}>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,70 @@
.toast {
position: fixed;
top: 2rem;
top: 50%;
left: 50%;
transform: translate(-50%, 0);
transform: translate(-50%, -50%);
margin: auto;
padding: 0.75rem 1rem;
width: 38.5rem;
height: 25.125rem;
padding: 1.5rem 1.5rem;
box-shadow: 4px 6px 30px 5px rgba(0, 0, 0, 0.15);
border-radius: 0.625rem;
z-index: 999;
border-radius: 1rem;
z-index: 1000;
display: flex;
align-items: center;
flex-direction: column;
justify-content: space-between;
}

.toastContent {
margin-bottom: 4rem;
display: flex;
align-items: center;
flex-direction: column;
}

.toasttext {
font-size: 1.0625rem;
height: 100%;
margin-left: 0.625rem;
color: white;
color: #00c48c;
text-align: center;
font-size: 1.75rem;
font-style: normal;
font-weight: 700;
line-height: normal;
margin-top: 1.5rem;
}

.successToast {
background-color: #00c48c;
background-color: white;
}

.errorToast {
background-color: #ff0000;
}

.continueButton {
background-color: #00c48c;
border: none;
border-radius: 9px;
padding: 0.4rem 2.5rem;
margin-bottom: 2.5rem;
}

.continueText {
color: #fff;
text-align: center;
font-size: 0.938rem;
font-style: normal;
font-weight: 500;
line-height: normal;
}

.closeButton {
background-color: white;
border: none;
align-self: flex-end;
border: none;
cursor: pointer;
background: none;
padding: 0;
margin-bottom: 1rem;
}
14 changes: 7 additions & 7 deletions frontend/src/components/UserDetail/UserDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const UserDetail = ({
const { refreshUser } = useContext(AuthContext);
const [showingToast, setToast] = useState(false);
const { refreshRiders } = useRiders();
const { toastType } = useToast();
const { toastType, showToast } = useToast();
const [confirmationModalisOpen, setConfirmationModalisOpen] = useState(false);

const openConfirmationModal = () => {
Expand All @@ -97,14 +97,14 @@ const UserDetail = ({
});
}
};
if (isShowing && rider) {
showToast(
`Rider ${rider.active ? 'activated' : 'deactivated'}.`,
toastType ? ToastStatus.SUCCESS : ToastStatus.ERROR
namanhboi marked this conversation as resolved.
Show resolved Hide resolved
);
}
return (
<div className={cn(styles.userDetail, { [styles.rider]: isRider })}>
{isShowing && rider ? (
<Toast
message={`Rider ${rider.active ? 'activated' : 'deactivated'}.`}
toastType={toastType ? ToastStatus.SUCCESS : ToastStatus.ERROR}
/>
) : null}
<div className={styles.imgContainer}>
{photoLink && photoLink !== '' ? (
<img
Expand Down
22 changes: 19 additions & 3 deletions frontend/src/context/toastContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ type toastStat = {
message: string;
showToast: (message: string, currentToastType: ToastStatus) => void;
toastType: boolean;
namanhboi marked this conversation as resolved.
Show resolved Hide resolved
setVisible: React.Dispatch<React.SetStateAction<boolean>>;
};

const initalState: toastStat = {
visible: false,
message: '',
showToast: function () {},
namanhboi marked this conversation as resolved.
Show resolved Hide resolved
toastType: false,
setVisible: function () {},
namanhboi marked this conversation as resolved.
Show resolved Hide resolved
};

const ToastContext = React.createContext(initalState);
Expand All @@ -35,14 +37,27 @@ export const ToastProvider = ({ children }: ToastProviderProps) => {
const showToast = (inputMessage: string, currentToastType: ToastStatus) => {
setMessage(inputMessage);
setVisible(true);

if (currentToastType == ToastStatus.ERROR) {
setToastType(false);
setTimeout(() => {
namanhboi marked this conversation as resolved.
Show resolved Hide resolved
setVisible(false);
}, 2000);
} else {
if (currentToastType == ToastStatus.SUCCESS) {
setToastType(true);
} else {
new Error('Invalid Toast type');
}
}
currentToastType == ToastStatus.ERROR
? setToastType(false)
: currentToastType == ToastStatus.SUCCESS
? setToastType(true)
: new Error('Invalid Toast type');
setTimeout(() => {
setVisible(false);
}, 2000);
// setTimeout(() => {
// setVisible(false);
// }, 2000);
};

namanhboi marked this conversation as resolved.
Show resolved Hide resolved
return (
Expand All @@ -52,6 +67,7 @@ export const ToastProvider = ({ children }: ToastProviderProps) => {
message,
showToast,
toastType,
setVisible,
}}
>
{children}
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/icons/other/green-check.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions frontend/src/icons/other/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ export { default as chevronLeft } from './chevron-left.svg';
export { default as block } from './blocked.svg';
export { default as red_trash } from './red-trash.svg';
export { default as search_icon } from './search.svg';
export { default as green_check } from './green-check.svg';
Loading