new table for settings and store blocked date there;

non admins can't enter avs before the blocked date
new table for survey
This commit is contained in:
Dobromir Popov
2024-06-16 23:33:49 +03:00
parent 901d577b9c
commit 8ca2000ee4
12 changed files with 205 additions and 50 deletions

View File

@ -17,11 +17,22 @@ export default function AvailabilityList({ publisher, showNew }) {
const [showAv, setShowAv] = useState(showNew || false);
const [selectedItem, setSelectedItem] = useState(null);
const [items, setItems] = useState(publisher.availabilities); // Convert items prop to state
const [blockedAvailabilityDate, setBlockedAvailabilityDate] = useState(null);
useEffect(() => {
console.log('items set to:', items?.map(item => item.id));
}, [items])
useEffect(() => {
axiosInstance.get(`/api/?action=settings&key=AvailabilityBlockDate`)
.then(({ data }) => {
setBlockedAvailabilityDate(new Date(data.value));
})
.catch(error => {
console.error("Error getting blocked date:", error);
});
}, []);
const toggleAv = () => setShowAv(!showAv);
const editAvailability = (item) => {
setSelectedItem(item);
@ -72,9 +83,16 @@ export default function AvailabilityList({ publisher, showNew }) {
{/* <button className="bg-blue-200 hover:bg-blue-300 text-blue-600 py-1 px-2 rounded inline-flex items-center" onClick={() => editAvailability(item)}>
<PencilSquareIcon className="h-6 w-6" />
</button> */}
<button className="bg-red-200 hover:bg-red-300 text-red-600 py-1 px-2 rounded ml-2 inline-flex items-center" onClick={() => deleteAvailability(item.id)}>
<TrashIcon className="h-6 w-6" />
</button>
{(blockedAvailabilityDate && new Date(item.startTime) < blockedAvailabilityDate) ? (
<button className="disabled bg-gray-200 hover:bg-gray-300 text-gray-600 py-1 px-2 rounded inline-flex items-center">
<TrashIcon className="h-6 w-6" />
</button>
) : (
<button className="bg-red-200 hover:bg-red-300 text-red-600 py-1 px-2 rounded ml-2 inline-flex items-center" onClick={() => deleteAvailability(item.id)}>
<TrashIcon className="h-6 w-6" />
</button>
)}
</td>
</tr>
))}