(wip) - show repeating events in calendar (admin)
script to get jwt signature for Apple ID
This commit is contained in:
40
pages/api/auth/apple-token.ts
Normal file
40
pages/api/auth/apple-token.ts
Normal file
@ -0,0 +1,40 @@
|
||||
// pages/api/auth/apple-token.js
|
||||
import jwt from 'jsonwebtoken';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
const dotenv = require("dotenv");
|
||||
|
||||
|
||||
export default async function handler(req, res) {
|
||||
if (req.method === 'GET') {
|
||||
try {
|
||||
const appleKey = fs.readFileSync(path.resolve('./_deploy/appleKey.p8'), 'utf8');
|
||||
|
||||
const token = jwt.sign({}, appleKey, {
|
||||
algorithm: 'ES256',
|
||||
expiresIn: '180d',
|
||||
issuer: process.env.APPLE_TEAM_ID,
|
||||
header: {
|
||||
alg: 'ES256',
|
||||
kid: process.env.APPLE_KEY_ID,
|
||||
},
|
||||
audience: 'https://appleid.apple.com',
|
||||
subject: process.env.APPLE_ID,
|
||||
});
|
||||
|
||||
// Redirect to Apple's authentication page, or send the token to the client to do so
|
||||
console.log(token);
|
||||
res.status(200).send({
|
||||
message: 'Generated token for Apple Sign In',
|
||||
token: token
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error signing in with Apple:', error);
|
||||
res.status(500).send({ error: 'Failed to sign in with Apple' });
|
||||
}
|
||||
} else {
|
||||
// Handle any non-GET requests
|
||||
res.setHeader('Allow', ['GET']);
|
||||
res.status(405).end(`Method ${req.method} Not Allowed`);
|
||||
}
|
||||
}
|
@ -161,8 +161,9 @@ export default async function handler(req, res) {
|
||||
res.status(200).json(publishers);
|
||||
break;
|
||||
case "filterPublishersNew":
|
||||
let includeOldAvailabilities = common.parseBool(req.query.includeOldAvailabilities);
|
||||
let results = await filterPublishersNew_Available(req.query.select, day,
|
||||
common.parseBool(req.query.isExactTime), common.parseBool(req.query.isForTheMonth));
|
||||
common.parseBool(req.query.isExactTime), common.parseBool(req.query.isForTheMonth), includeOldAvailabilities);
|
||||
res.status(200).json(results);
|
||||
break;
|
||||
|
||||
@ -461,8 +462,8 @@ export async function getMonthlyStatistics(selectFields, filterDate) {
|
||||
}
|
||||
|
||||
|
||||
export async function filterPublishersNew_Available(selectFields, filterDate, isExactTime = false, isForTheMonth = false, isWithStats = true) {
|
||||
return data.filterPublishersNew(selectFields, filterDate, isExactTime, isForTheMonth, isWithStats);
|
||||
export async function filterPublishersNew_Available(selectFields, filterDate, isExactTime = false, isForTheMonth = false, isWithStats = true, includeOldAvailabilities = false) {
|
||||
return data.filterPublishersNew(selectFields, filterDate, isExactTime, isForTheMonth, isWithStats, includeOldAvailabilities);
|
||||
}
|
||||
|
||||
// availabilites filter:
|
||||
|
@ -76,15 +76,15 @@ export default function CalendarPage({ initialEvents, initialShifts }) {
|
||||
const [modalPub, setModalPub] = useState(null);
|
||||
|
||||
// ------------------ no assignments checkbox ------------------
|
||||
const [isCheckboxChecked, setIsCheckboxChecked] = useState(false);
|
||||
const [filterShowWithoutAssignments, setFilterShowWithoutAssignments] = useState(false);
|
||||
const handleCheckboxChange = (event) => {
|
||||
setIsCheckboxChecked(!isCheckboxChecked); // Toggle the checkbox state
|
||||
setFilterShowWithoutAssignments(!filterShowWithoutAssignments); // Toggle the checkbox state
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
console.log("checkbox checked: " + isCheckboxChecked);
|
||||
console.log("checkbox checked: " + filterShowWithoutAssignments);
|
||||
handleCalDateChange(value); // Call handleCalDateChange whenever isCheckboxChecked changes
|
||||
}, [isCheckboxChecked]); // Dependency array
|
||||
}, [filterShowWithoutAssignments]); // Dependency array
|
||||
|
||||
const [selectedMonth, setSelectedMonth] = useState(new Date().getMonth());
|
||||
useEffect(() => {
|
||||
@ -99,7 +99,7 @@ export default function CalendarPage({ initialEvents, initialShifts }) {
|
||||
var date = new Date(common.getDateFromDateTime(selectedDate));//ToDo: check if seting the timezone affects the selectedDate?!
|
||||
var dateStr = common.getISODateOnly(date);
|
||||
console.log("Setting date to '" + date.toLocaleDateString() + "' from '" + selectedDate.toLocaleDateString() + "'. ISO: " + date.toISOString(), "locale ISO:", common.getISODateOnly(date));
|
||||
if (isCheckboxChecked) {
|
||||
if (filterShowWithoutAssignments) {
|
||||
console.log(`getting unassigned publishers for ${common.getMonthName(date.getMonth())} ${date.getFullYear()}`);
|
||||
const { data: availablePubsForDate } = await axiosInstance.get(`/api/?action=getUnassignedPublishers&date=${dateStr}&select=id,firstName,lastName,isActive,desiredShiftsPerMonth`);
|
||||
setAvailablePubs(availablePubsForDate);
|
||||
@ -110,7 +110,7 @@ export default function CalendarPage({ initialEvents, initialShifts }) {
|
||||
const { data: shiftsForDate } = await axiosInstance.get(`/api/?action=getShiftsForDay&date=${dateStr}`);
|
||||
setShifts(shiftsForDate);
|
||||
setIsPublished(shiftsForDate.some(shift => shift.isPublished));
|
||||
let { data: availablePubsForDate } = await axiosInstance.get(`/api/?action=filterPublishersNew&date=${dateStr}&select=id,firstName,lastName,isActive,desiredShiftsPerMonth`);
|
||||
let { data: availablePubsForDate } = await axiosInstance.get(`/api/?action=filterPublishersNew&date=${dateStr}&select=id,firstName,lastName,isActive,desiredShiftsPerMonth&includeOldAvailabilities=${filterShowWithoutAssignments}`);
|
||||
|
||||
availablePubsForDate.forEach(pub => {
|
||||
pub.canTransport = pub.availabilities.some(av =>
|
||||
@ -664,9 +664,10 @@ export default function CalendarPage({ initialEvents, initialShifts }) {
|
||||
|
||||
<h2 className="text-lg font-semibold mb-4">Достъпни за този ден: <span className="text-blue-600">{availablePubs.length}</span></h2>
|
||||
<label className="toggle pb-3">
|
||||
<input type="checkbox" className="toggle-checkbox" onChange={handleCheckboxChange} />
|
||||
<input type="checkbox" className="toggle-checkbox" id="filterShowWithoutAssignments" onChange={handleCheckboxChange} />
|
||||
<span className="toggle-slider m-1">без назначения за месеца</span>
|
||||
|
||||
<input type="checkbox" className="toggle-checkbox" id="filterIncludeOldAvailabilities" onChange={handleCheckboxChange} />
|
||||
<span className="toggle-slider m-1">със стари предпочитания</span>
|
||||
</label>
|
||||
<ul className="w-full max-w-md">
|
||||
{Array.isArray(availablePubs) && availablePubs?.map((pub, index) => {
|
||||
@ -891,6 +892,7 @@ export default function CalendarPage({ initialEvents, initialShifts }) {
|
||||
|
||||
import axiosServer from '../../../src/axiosServer';
|
||||
import { start } from 'repl';
|
||||
import { filter } from 'jszip';
|
||||
export const getServerSideProps = async (context) => {
|
||||
const axios = await axiosServer(context);
|
||||
// const baseUrl = common.getBaseUrl();
|
||||
|
Reference in New Issue
Block a user