-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathDropOrUndropUser.tsx
118 lines (112 loc) · 4 KB
/
DropOrUndropUser.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import React, { useState } from 'react';
import { useTranslation } from 'react-i18next';
import Button from './Buttons';
interface DropOrUndropUserProps {
subject: string;
title: string;
drop?: boolean;
loading: boolean;
removalReason?: string;
setRemovalReason?: React.Dispatch<React.SetStateAction<string>>;
onSubmit: (data: React.MouseEvent<HTMLButtonElement>) => void;
onClose: () => void;
}
function DropOrUndropUser({
subject,
title,
drop,
loading,
removalReason,
setRemovalReason,
onSubmit,
onClose,
}: DropOrUndropUserProps) {
const { t } = useTranslation();
const handleConfirm = (e: React.MouseEvent<HTMLButtonElement>) => {
e.stopPropagation();
if (onSubmit) onSubmit(e);
};
return (
<div className="h-screen w-screen bg-black bg-opacity-30 backdrop-blur-sm fixed top-0 left-0 z-20 flex items-center justify-center px-4">
<div className="w-full p-4 pb-8 bg-white rounded-lg dark:bg-dark-bg sm:w-3/4 xl:w-4/12">
<div className="flex flex-wrap items-center justify-center w-full card-title ">
<h3 className="w-11/12 text-sm font-bold text-center dark:text-white ">
{t(subject)}
</h3>
<hr className="w-full my-3 border-b bg-primary" />
</div>
<div className="card-body w-full">
<form className="px-8 py-3 w-full">
<div className="flex flex-wrap items-center justify-center w-full card-title ">
<h3 className="w-11/12 text-sm font-bold text-center dark:text-white ">
{t(title)}
</h3>
</div>
{/* Reason input field */}
{drop && setRemovalReason && (
<div className="mt-4">
<input
type="text"
className="mt-1 p-2 block w-full border rounded-md shadow-sm focus:ring focus:ring-opacity-50 focus:ring-primary dark:bg-dark-bg dark:border-gray-600 dark:text-white"
placeholder={t('Enter reason')}
value={removalReason}
onChange={(e: React.ChangeEvent<HTMLInputElement>) =>
setRemovalReason(e.target.value)
}
id="removalReason"
/>
<p
id="errorMessage"
className="text-red-500 text-xs mt-1 hidden"
>
Reason is required!
</p>
</div>
)}
<div className="flex justify-between w-full pt-3">
<Button
data-testid="removeModel2"
variant="info"
size="sm"
style="w-[8rem] h-[2.3rem] text-sm p-0 mx-0 flex justify-center items-center"
onClick={() => {
if (drop && setRemovalReason) {
setRemovalReason('');
document
.getElementById('errorMessage')!
.classList.add('hidden');
}
onClose();
}}
>
{t('Cancel')}
</Button>
<Button
variant="primary"
size="sm"
style="w-[8rem] h-[2.3rem] text-sm p-0 mx-0 flex justify-center items-center"
onClick={() => {
if (removalReason && !removalReason.trim() && drop) {
document
.getElementById('errorMessage')!
.classList.remove('hidden');
} else {
handleConfirm(
new MouseEvent(
'click',
) as unknown as React.MouseEvent<HTMLButtonElement>,
);
}
}}
loading={loading}
>
{loading ? t('Loading') : t('Proceed')}
</Button>
</div>
</form>
</div>
</div>
</div>
);
}
export default DropOrUndropUser;