Merge branch 'production'

This commit is contained in:
Dobromir Popov
2024-07-06 19:18:22 +03:00
12 changed files with 120 additions and 218 deletions

View File

@ -27,7 +27,7 @@ class ErrorBoundary extends React.Component {
render() {
if (this.state.hasError) {
// Render any custom fallback UI
return <h1>Нещо се обърка при изтриването. Моля, опитай отново и се свържете с нас ако проблема продължи. </h1>;
return <h1>Нещо се обърка. Моля, опитай отново и се свържете с нас ако проблема продължи. </h1>;
}
return this.props.children;

View File

@ -6,7 +6,7 @@ import e from 'express';
import ProtectedRoute from './protectedRoute';
import { UserRole } from '@prisma/client';
function PwaManager({ subs }) {
function PwaManager({ userId, subs }) {
//ToDo: for iOS, try to use apn? https://github.com/node-apn/node-apn/blob/master/doc/apn.markdown
const isSupported = () =>
'Notification' in window &&
@ -271,6 +271,37 @@ function PwaManager({ subs }) {
{ action: 'close', title: 'Затвори', icon: '❌' }]
})
});
/*
await fetch('/api/notify', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
id: pub.id,
message: "Тестово съобщение",
title: "Това е тестово съобщение от https://sofia.mwitnessing.com",
actions: [
{ action: 'OK', title: 'OK', icon: '✅' },
{ action: 'close', title: 'Затвори', icon: '❌' }
]
// actions: [
// {
// title: 'Open URL',
// action: 'open_url',
// icon: '/images/open-url.png'
// },
// {
// title: 'Dismiss',
// action: 'dismiss',
// icon: '/images/dismiss.png'
// }
// ]
})
})
*/
};
// async function sendTestReminder(event: MouseEvent<HTMLButtonElement, MouseEvent>): Promise<void> {
@ -382,7 +413,7 @@ function PwaManager({ subs }) {
>
Тестово уведомление
</button>
</div>
</div >
{isAdmin &&
<div>
{/* <button
@ -403,28 +434,31 @@ function PwaManager({ subs }) {
</button> */}
</div>
}
{notificationPermission !== "granted" && (
<button
onClick={togglePushNotifications}
className={`text-xs py-1 px-2 rounded-full focus:outline-none transition duration-150 ease-in-out ${notificationPermission === "denied" ? 'bg-red-500 hover:bg-red-700 text-white' : 'bg-green-500 hover:bg-green-700 text-white'
}`}
>
{notificationPermission === "denied" ? 'Notifications Denied!' : 'Enable Notifications'}
</button>
)}
{
notificationPermission !== "granted" && (
<button
onClick={togglePushNotifications}
className={`text-xs py-1 px-2 rounded-full focus:outline-none transition duration-150 ease-in-out ${notificationPermission === "denied" ? 'bg-red-500 hover:bg-red-700 text-white' : 'bg-green-500 hover:bg-green-700 text-white'
}`}
>
{notificationPermission === "denied" ? 'Notifications Denied!' : 'Enable Notifications'}
</button>
)
}
{isAdmin && <div>
<div>
<a href="https://t.me/mwhitnessing_bot" className="inline-flex items-center ml-4" target="_blank">
<img src="/content/icons/telegram-svgrepo-com.svg" alt="Телеграм" width="32" height="32" className="align-middle" />
<span className="align-middle">Телеграм</span>
</a>
{
isAdmin && <div>
<div>
<a href="https://t.me/mwhitnessing_bot" className="inline-flex items-center ml-4" target="_blank">
<img src="/content/icons/telegram-svgrepo-com.svg" alt="Телеграм" width="32" height="32" className="align-middle" />
<span className="align-middle">Телеграм</span>
</a>
<a href="/api/auth/apple-signin" className="inline-flex items-center ml-4 bg-gray-100 button" target="_blank">
<span className="align-middle">Apple sign-in</span>
</a>
<a href="/api/auth/apple-signin" className="inline-flex items-center ml-4 bg-gray-100 button" target="_blank">
<span className="align-middle">Apple sign-in</span>
</a>
</div>
</div>
</div>
}
</>
);

View File

@ -303,7 +303,8 @@ export default function PublisherForm({ item, me }) {
{/* In-App notifications group */}
<div className="mb-4">
<h3 className="text-md font-semibold mb-2">Известия в приложението</h3>
<PwaManager />
<PwaManager userId={publisher.userId || session.user.id} />
</div>
</fieldset>
</div>

View File

@ -185,5 +185,4 @@ const removeAssignment = async (publisher, shiftId) => {
}
}
export default PublisherShiftsModal;

View File

@ -62,8 +62,8 @@ const SurveyForm: React.FC<SurveyFormProps> = ({ existingItem }) => {
...existingItem,
content: existingItem?.content || "Нова анкета",
answers: existingItem?.answers.split(",") || [],
publicFrom: existingItem?.publicFrom ? dayjs(existingItem.publicFrom).toISOString() : new Date().toISOString(),
publicUntil: existingItem?.publicUntil ? dayjs(existingItem.publicUntil).toISOString() : new Date().toISOString(),
publicFrom: existingItem?.publicFrom ? dayjs(existingItem.publicFrom).toISOString() : '',
publicUntil: existingItem?.publicUntil ? dayjs(existingItem.publicUntil).toISOString() : null,
});
@ -104,7 +104,7 @@ const SurveyForm: React.FC<SurveyFormProps> = ({ existingItem }) => {
}
else {
//get all publisherIds and create a message for each
const messages = pubs.data.map(pub => {
const messages = pubs.map(pub => {
return {
publisherId: pub.id,
content: JSON.stringify({ message: item.content, options: item.answers }),
@ -236,13 +236,16 @@ const SurveyForm: React.FC<SurveyFormProps> = ({ existingItem }) => {
<label className="block text-gray-700 text-sm font-bold mb-2" htmlFor="date">
Видима от
</label>
<DatePicker className="textbox form-input px-4 py-2 rounded" name="publicFrom" onChange={(newDate) => handleDateChange('publicFrom', newDate)} value={dayjs(item?.publicFrom)} />
<DatePicker className="textbox form-input px-4 py-2 rounded" name="publicFrom" onChange={(newDate) => handleDateChange('publicFrom', newDate)}
value={item && item.publicFrom ? dayjs(item.publicFrom) : null} />
</div>
<div className="mb-4">
<label className="block text-gray-700 text-sm font-bold mb-2" htmlFor="date">
Видима до
</label>
<DatePicker className="textbox form-input px-4 py-2 rounded" name="publicUntil" onChange={(newDate) => handleDateChange('publicUntil', newDate)} value={dayjs(item?.publicUntil)} />
<DatePicker className="textbox form-input px-4 py-2 rounded" name="publicUntil" onChange={(newDate) => handleDateChange('publicUntil', newDate)}
value={item && item.publicUntil ? dayjs(item.publicUntil) : null}
/>
</div>
<div className="mb-4">
<label className="block text-gray-700 text-sm font-bold mb-2" htmlFor="content">