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

Update snackbar to include a react node #647

Merged
merged 1 commit into from
Nov 19, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 4 additions & 5 deletions app/src/contexts/dialogContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import CloseIcon from '@material-ui/icons/Close';
import { Color } from '@material-ui/lab/Alert';
import { ErrorDialog, IErrorDialogProps } from 'components/dialog/ErrorDialog';
import YesNoDialog, { IYesNoDialogProps } from 'components/dialog/YesNoDialog';
import React, { createContext, useState } from 'react';
import React, { createContext, ReactNode, useState } from 'react';

export interface IDialogContext {
/**
Expand Down Expand Up @@ -55,12 +55,11 @@ export interface IDialogContext {
}

export interface ISnackbarProps {
snackbarText: string;
open: boolean;
onClose: () => void;
severity?: Color;
color?: Color;
snackbarMessage?: string;
snackbarMessage: ReactNode;
}

export const defaultYesNoDialogProps: IYesNoDialogProps = {
Expand Down Expand Up @@ -91,7 +90,7 @@ export const defaultErrorDialogProps: IErrorDialogProps = {
};

export const defaultSnackbarProps: ISnackbarProps = {
snackbarText: '',
snackbarMessage: '',
open: false,
onClose: () => {
// default do nothing
Expand Down Expand Up @@ -159,7 +158,7 @@ export const DialogContextProvider: React.FC = (props) => {
open={snackbarProps.open}
autoHideDuration={6000}
onClose={() => setSnackbar({ open: false })}
message={snackbarProps.snackbarText}
message={snackbarProps.snackbarMessage}
action={
<React.Fragment>
<IconButton size="small" aria-label="close" color="inherit" onClick={() => setSnackbar({ open: false })}>
Expand Down
15 changes: 12 additions & 3 deletions app/src/features/admin/users/ActiveUsersList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const ActiveUsersList: React.FC<IActiveUsersListProps> = (props) => {
dialogContext.setSnackbar({ ...textDialogProps, open: true });
};

const handleRemoveUserClick = (row: any) => {
const handleRemoveUserClick = (row: IGetUserResponse) => {
dialogContext.setYesNoDialog({
dialogTitle: 'Remove user?',
dialogContent: (
Expand Down Expand Up @@ -90,14 +90,23 @@ const ActiveUsersList: React.FC<IActiveUsersListProps> = (props) => {
});
};

const deActivateSystemUser = async (user: any) => {
const deActivateSystemUser = async (user: IGetUserResponse) => {
if (!user?.id) {
return;
}
try {
await biohubApi.user.deleteSystemUser(user.id);

showSnackBar({ snackbarText: 'Success! User removed', snackbarMessage: 'User successfully removed', open: true });
showSnackBar({
snackbarMessage: (
<>
<Typography variant="body2" component="div">
User <strong>{user.user_identifier}</strong> removed.
</Typography>
</>
),
open: true
});

props.getUsers(true);
} catch (error) {
Expand Down