fix statistics page
This commit is contained in:
@ -19,7 +19,7 @@ function ContactsPage({ publishers }) {
|
||||
<Layout>
|
||||
<ProtectedRoute allowedRoles={[UserRole.ADMIN, UserRole.POWERUSER, UserRole.USER]}>
|
||||
<div className="container mx-auto p-4">
|
||||
<h1 className="text-xl font-semibold mb-4">Контакти</h1>
|
||||
<h1 className="text-xl font-semibold mb-4">Участници</h1>
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Търси по име, имейл или телефон..."
|
||||
|
@ -20,7 +20,7 @@ function ContactsPage({ publishers }) {
|
||||
<Layout>
|
||||
<ProtectedRoute allowedRoles={[UserRole.ADMIN, UserRole.POWERUSER, UserRole.USER]}>
|
||||
<div className="container mx-auto p-4">
|
||||
<h1 className="text-xl font-semibold mb-4">Контакти</h1>
|
||||
<h1 className="text-xl font-semibold mb-4">Статистика</h1>
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Търси по име, имейл или телефон..."
|
||||
@ -33,32 +33,26 @@ function ContactsPage({ publishers }) {
|
||||
<thead>
|
||||
<tr>
|
||||
<th className="border-b font-medium p-4 pl-8 pt-0 pb-3">Име</th>
|
||||
<th className="border-b font-medium p-4 pt-0 pb-3">Имейл</th>
|
||||
<th className="border-b font-medium p-4 pt-0 pb-3">Телефон</th>
|
||||
<th className="border-b font-medium p-4 pt-0 pb-3">Възможности</th>
|
||||
<th className="border-b font-medium p-4 pt-0 pb-3">Участия</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{filteredPublishers.map((publisher) => (
|
||||
<tr key={publisher.id}>
|
||||
<td className="border-b p-4 pl-8">{publisher.firstName} {publisher.lastName}</td>
|
||||
{filteredPublishers.map((pub) => (
|
||||
<tr key={pub.id}>
|
||||
<td className="border-b p-4 pl-8">{pub.firstName} {pub.lastName}</td>
|
||||
<td className="border-b p-4">
|
||||
<a href={`mailto:${publisher.email}`} className="text-blue-500">{publisher.email}</a>
|
||||
<span title="Възможност: часове | дни" className={`badge py-1 px-2 rounded-md text-xs ${pub.currentMonthAvailabilityHoursCount || pub.currentMonthAvailabilityDaysCount ? 'bg-teal-500 text-white' : 'bg-teal-200 text-gray-300'} hover:underline`} >
|
||||
{pub.currentMonthAvailabilityDaysCount || 0} | {pub.currentMonthAvailabilityHoursCount || 0}
|
||||
</span>
|
||||
</td>
|
||||
<td className="border-b p-4">
|
||||
<div className="flex items-center justify-between">
|
||||
<span className={common.isValidPhoneNumber(publisher.phone) ? '' : 'text-red-500'}>{publisher.phone}</span>
|
||||
<div className="flex items-center">
|
||||
<a href={`tel:${publisher.phone}`} className="inline-block p-2 mr-2">
|
||||
<i className="fas fa-phone-alt text-blue-500 text-xl" title="Обаждане"></i>
|
||||
</a>
|
||||
<a href={`https://wa.me/${publisher.phone}`} className="inline-block p-2 mr-2">
|
||||
<i className="fab fa-whatsapp text-green-500 text-xl" title="WhatsApp"></i>
|
||||
</a>
|
||||
{publisher.phone ? (
|
||||
<a href={`viber://chat/?number=%2B${publisher.phone.startsWith('+') ? publisher.phone.substring(1) : publisher.phone}`} className="inline-block p-2">
|
||||
<i className="fab fa-viber text-purple-500 text-xl" title="Viber"></i>
|
||||
</a>
|
||||
) : null}
|
||||
<span title="участия тази седмица" className={`badge py-1 px-2 rounded-full text-xs ${pub.currentWeekAssignments ? 'bg-yellow-500 text-white' : 'bg-yellow-200 text-gray-400'}`}>{pub.currentWeekAssignments || 0}</span>
|
||||
<span title="участия този месец" className={`badge py-1 px-2 rounded-full text-xs ${pub.currentMonthAssignments ? 'bg-green-500 text-white' : 'bg-green-200 text-gray-400'}`}>{pub.currentMonthAssignments || 0}</span>
|
||||
<span tooltip="участия миналия месец" title="участия миналия месец" className={`badge py-1 px-2 rounded-full text-xs ${pub.previousMonthAssignments ? 'bg-blue-500 text-white' : 'bg-blue-200 text-gray-400'}`}>{pub.previousMonthAssignments || 0}</span>
|
||||
<button tooltip="желани участия този месец" title="желани участия" className={`badge py-1 px-2 rounded-md text-xs ${pub.desiredShiftsPerMonth ? 'bg-purple-500 text-white' : 'bg-purple-200 text-gray-400'}`}>{pub.desiredShiftsPerMonth || 0}</button>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
@ -79,12 +73,31 @@ export default ContactsPage;
|
||||
export const getServerSideProps = async (context) => {
|
||||
const dateStr = new Date().toISOString().split('T')[0];
|
||||
|
||||
let publishers = await filterPublishers('id,firstName,lastName,isactive,desiredShiftsPerMonth', "", new Date(), true, true);
|
||||
let publishers = await filterPublishers('id,firstName,lastName,isactive,desiredShiftsPerMonth', "", new Date(), true, true, false);
|
||||
|
||||
// const axios = await axiosServer(context);
|
||||
// const { data: publishers } = await axios.get(`api/?action=filterPublishers&assignments=true&availabilities=true&date=${dateStr}&select=id,firstName,lastName,isactive,desiredShiftsPerMonth`);
|
||||
|
||||
// api/index?action=filterPublishers&assignments=true&availabilities=true&date=2024-03-14&select=id%2CfirstName%2ClastName%2Cisactive%2CdesiredShiftsPerMonth
|
||||
publishers.forEach(publisher => {
|
||||
publisher.desiredShiftsPerMonth = publisher.desiredShiftsPerMonth || 0;
|
||||
publisher.assignments = publisher.assignments || [];
|
||||
publisher.availabilities = publisher.availabilities || [];
|
||||
//serialize dates in publisher.assignments and publisher.availabilities
|
||||
publisher.assignments.forEach(assignment => {
|
||||
if (assignment.shift && assignment.shift.startTime) {
|
||||
assignment.shift.startTime = assignment.shift.startTime.toISOString();
|
||||
assignment.shift.endTime = assignment.shift.endTime.toISOString();
|
||||
}
|
||||
});
|
||||
publisher.availabilities.forEach(availability => {
|
||||
if (availability.startTime) {
|
||||
availability.startTime = availability.startTime.toISOString();
|
||||
availability.endTime = availability.endTime.toISOString();
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
return {
|
||||
props: {
|
||||
|
@ -111,6 +111,7 @@ model Publisher {
|
||||
town String?
|
||||
comments String?
|
||||
reports Report[]
|
||||
Message Message[]
|
||||
}
|
||||
|
||||
model Availability {
|
||||
@ -223,6 +224,25 @@ model Report {
|
||||
@@map("Report")
|
||||
}
|
||||
|
||||
//message types
|
||||
enum MessageType {
|
||||
Email
|
||||
SMS
|
||||
Push
|
||||
InApp
|
||||
}
|
||||
|
||||
model Message {
|
||||
id Int @id @default(autoincrement())
|
||||
publisher Publisher @relation(fields: [publisherId], references: [id])
|
||||
publisherId String
|
||||
date DateTime
|
||||
content String
|
||||
isRead Boolean @default(false)
|
||||
isPublic Boolean @default(false)
|
||||
type MessageType @default(Email)
|
||||
}
|
||||
|
||||
//user auth and session management
|
||||
model User {
|
||||
id String @id @default(cuid())
|
||||
|
Reference in New Issue
Block a user