Skip to content

Commit 6f3d40b

Browse files
committed
Login page migrated to tsx
1 parent 183eb64 commit 6f3d40b

5 files changed

Lines changed: 18 additions & 27 deletions

File tree

Client/src/api/swalAlert.ts

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,12 @@
1-
import Swal from 'sweetalert2';
1+
import Swal, { SweetAlertIcon, SweetAlertPosition } from 'sweetalert2';
2+
3+
24

3-
type SwalIcon = 'success' | 'error' | 'warning' | 'info' | 'question';
4-
type SwalPosition =
5-
| 'top'
6-
| 'top-start'
7-
| 'top-end'
8-
| 'center'
9-
| 'center-start'
10-
| 'center-end'
11-
| 'bottom'
12-
| 'bottom-start'
13-
| 'bottom-end';
145

156
const swalAlert = (
16-
icon: SwalIcon,
7+
icon: SweetAlertIcon,
178
title: string,
18-
position: SwalPosition = 'center'
9+
position: SweetAlertPosition = 'center'
1910
) => {
2011
Swal.fire({
2112
position,
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { toast } from 'react-toastify';
66

77

88
// create a user to the database
9-
export const createOrUpdateUser = async (userInfo) => {
9+
export const createOrUpdateUser = async (userInfo : any) => {
1010
try {
1111
const res = await axiosApi.put('/users', userInfo);
1212

@@ -18,15 +18,15 @@ export const createOrUpdateUser = async (userInfo) => {
1818
toast.success('User info updated successfully');
1919
}
2020
return res;
21-
} catch (error) {
21+
} catch (error : any) {
2222
console.error(error);
2323
swalAlert('error', error.message);
2424
throw error;
2525
}
2626
};
2727

2828
// post publisher info
29-
export const postPublisherInfo = async (publisherData) => {
29+
export const postPublisherInfo = async (publisherData : any) => {
3030
try {
3131
//console.log(publisherData)
3232

@@ -37,7 +37,7 @@ export const postPublisherInfo = async (publisherData) => {
3737
if (res.data.insertedId) {
3838
swalAlert('success', 'Publisher created successfully');
3939
}
40-
} catch (error) {
40+
} catch (error : any) {
4141
console.error(error);
4242
swalAlert('error', error.message);
4343
}
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import PropTypes from 'prop-types';
21
import { Link } from 'react-router-dom';
32
import logo from '../assets/logo3.png';
43

5-
const LoginRegisterTitle = ({ title }) => {
4+
const LoginRegisterTitle = ({ title } : {title: string}) => {
65
return (
76
<div>
87
<Link to='/'>
@@ -15,8 +14,5 @@ const LoginRegisterTitle = ({ title }) => {
1514
);
1615
};
1716

18-
LoginRegisterTitle.propTypes = {
19-
title: PropTypes.string.isRequired,
20-
};
2117

2218
export default LoginRegisterTitle;
Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,13 @@ import { ToastContainer } from 'react-toastify';
1212
import 'react-toastify/dist/ReactToastify.css';
1313

1414
import { toast } from 'react-toastify';
15-
import { createOrUpdateUser } from '../../api/userApi';
1615
import swalAlert from '../../api/swalAlert';
1716

17+
type FormValues = {
18+
email: string;
19+
password: string;
20+
};
21+
1822
const Login = () => {
1923
const [showPassword, setShowPassword] = useState(false);
2024

@@ -29,15 +33,15 @@ const Login = () => {
2933
register,
3034
handleSubmit,
3135
formState: { errors },
32-
} = useForm();
36+
} = useForm<FormValues>();
3337

34-
const onSubmit = async ({ email, password }) => {
38+
const onSubmit = async ({ email, password } : { email: string; password: string }) => {
3539
try {
3640
setLoading(true);
3741
await logInUser(email, password);
3842
swalAlert('success', 'Sign Up Successful', 'top-right');
3943
navigate(from);
40-
} catch (err) {
44+
} catch (err : any ) {
4145
//console.log(err);
4246
toast.error(err.message);
4347
setLoading(false);

0 commit comments

Comments
 (0)