-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd-comment.tsx
More file actions
112 lines (101 loc) · 3.85 KB
/
Copy pathadd-comment.tsx
File metadata and controls
112 lines (101 loc) · 3.85 KB
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
import { useState } from 'react';
import { useUser } from '@/hooks/useUser'; // Import your user hook
import axiosApi from '@/lib/apiSetup';
interface AddCommentProps {
onGetData: () => void;
onAddEvent: () => void;
}
export default function AddComment(props: AddCommentProps) {
const [comment, setComment] = useState('');
const [startTime, setStartTime] = useState(new Date());
const [endTime, setEndTime] = useState(new Date());
const [isReservable, setIsReservable] = useState<boolean>(false);
const { user } = useUser(); // Get current user
const addComment = () => {
if (!comment || !startTime || !endTime) {
return;
}
axiosApi
.post('/comments', {
comment: comment,
startTime: startTime,
endTime: endTime,
isReservable: Boolean(isReservable),
})
.then(() => {
props.onGetData();
setComment('');
setStartTime(new Date());
setEndTime(new Date());
setIsReservable(false);
props.onAddEvent();
})
.catch((error) => {
console.error(error.response.data);
console.error(error.response.status);
});
};
if (!user || user.role !== 'ADMIN') {
return <div className='text-red-600 dark:text-red-400'>Only admins can add comments.</div>;
}
// For add-comment.tsx - replace the return part with:
return (
<div className='space-y-5'>
<div>
<label htmlFor='comment' className='block text-sm font-medium text-black dark:text-zinc-300 mb-1'>
Komment
</label>
<input
id='comment'
type='text'
placeholder='Írja be a kommentet...'
className='bg-white hover:bg-slate-200 dark:bg-zinc-700 dark:hover:bg-zinc-600 text-black dark:text-zinc-200 border border-zinc-600 w-full px-3 py-2 rounded-md focus:ring-2 focus:ring-ring focus:border-transparent'
onChange={(e) => setComment(e.target.value)}
value={comment}
/>
</div>
<div className='grid grid-cols-2 gap-4'>
<div className='flex flex-col'>
<label htmlFor='begin' className='block text-sm font-medium text-black dark:text-zinc-300 mb-1'>
Kezdés
</label>
<input
id='begin'
className='bg-white hover:bg-slate-200 dark:bg-zinc-700 dark:hover:bg-zinc-600 text-black dark:text-zinc-200 rounded-md border border-zinc-600 px-3 py-2 focus:ring-2 focus:ring-ring focus:border-transparent'
type='datetime-local'
onChange={(e) => setStartTime(new Date(e.target.value))}
/>
</div>
<div className='flex flex-col'>
<label htmlFor='end' className='block text-sm font-medium text-black dark:text-zinc-300 mb-1'>
Vége
</label>
<input
id='end'
className='bg-white hover:bg-slate-200 dark:bg-zinc-700 dark:hover:bg-zinc-600 text-black dark:text-zinc-200 rounded-md border border-zinc-600 px-3 py-2 focus:ring-2 focus:ring-ring focus:border-transparent'
type='datetime-local'
onChange={(e) => setEndTime(new Date(e.target.value))}
/>
</div>
</div>
<div className='flex items-center'>
<input
id='reservable'
className='h-5 w-5 text-primary border-zinc-600 rounded focus:ring-ring bg-zinc-700'
type='checkbox'
onChange={(e) => setIsReservable(e.target.checked)}
checked={isReservable}
/>
<label htmlFor='reservable' className='ml-2 block text-sm font-medium text-black dark:text-zinc-300'>
Foglalható
</label>
</div>
<button
className='w-full rounded-md bg-primary hover:bg-primary/90 text-primary-foreground font-semibold py-3 mt-4 transition-colors shadow-lg'
onClick={addComment}
>
Komment hozzáadása
</button>
</div>
);
}