Skip to content

Commit

Permalink
added add action for admin
Browse files Browse the repository at this point in the history
  • Loading branch information
aliknot committed Aug 1, 2022
1 parent 6068b67 commit 5388391
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
59 changes: 59 additions & 0 deletions src/pages/admin/Actions/Add/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { useState } from 'react';
import { insertData } from '../../../../firebase/transportLayer';
import Button from '../../../../core/Button';
import Label from '../../../../core/Label';
import Modal from '../../../../core/Modal';
import styles from './styles.module.scss';
import Input from '../../../../core/Input';

interface AddProps {
getUsers: () => void;
}

const Add = ({ getUsers }: AddProps) => {
const [isAddModalShown, setIsAddModalShown] = useState<boolean>(false);
const [fullname, setFullname] = useState<string>('');
const [password, setPassword] = useState<string>('');
const [description, setDescription] = useState<string>('');

const handleInsertData = () => {
const insertDataTemp = { fullname, password, description };
insertData(insertDataTemp).then(() => {
setIsAddModalShown(false);
getUsers();
});
};

return (
<>
<Button handleClick={() => setIsAddModalShown(true)}>Add</Button>
<Modal isShown={isAddModalShown} handleClose={() => setIsAddModalShown(false)}>
<h2 className={styles.subtitle}>Add</h2>
<Input
handleChange={(event) => setFullname(event.target.value)}
inputValue={fullname}
type='text'
label={<Label>Fullname: </Label>}
/>
<Input
handleChange={(event) => setPassword(event.target.value)}
inputValue={password}
type='password'
label={<Label>Password: </Label>}
/>
<Input
handleChange={(event) => setDescription(event.target.value)}
inputValue={description}
type='textarea'
label={<Label>Description: </Label>}
/>
<div className={styles.modalActions}>
<Button handleClick={() => setIsAddModalShown(false)}>Close</Button>
<Button handleClick={handleInsertData}>Save</Button>
</div>
</Modal>
</>
);
};

export default Add;
13 changes: 13 additions & 0 deletions src/pages/admin/Actions/Add/styles.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.subtitle {
text-align: left;
margin-bottom: 32px;
}

.modalActions {
width: 100%;
display: flex;
align-items: flex-end;
margin-top: 16px;
padding-top: 16px;
border-top: 1px solid gray;
}

0 comments on commit 5388391

Please sign in to comment.