diff --git a/.env b/.env index eec3b83..d0883ef 100644 --- a/.env +++ b/.env @@ -24,10 +24,13 @@ AZURE_AD_CLIENT_SECRET=5ic8Q~GQmW-IUhuxzVGx3BE-i30GXDSpjfMHcb~z #client secret v AZURE_AD_TENANT_ID=f69d1a93-bfba-498a-9b60-e87c1bc26276 -APPLE_ID= -APPLE_TEAM_ID= +APPLE_ID=com.mwhitnessing.sofia +APPLE_SECRET=eyJhbGciOiJFUzI1NiIsImtpZCI6IlRCM1YzNTVHNVkifQ.eyJhdWQiOiJodHRwczovL2FwcGxlaWQuYXBwbGUuY29tIiwiaXNzIjoiWEM1N1A5U1hESyIsImlhdCI6MTcxMjE3ODM0MiwiZXhwIjoxNzI3NzMwMzQzLCJzdWIiOiJjb20ubXdoaXRuZXNzaW5nLnNvZmlhIn0.XceA0qUQi0tXg0GM_LkJkpNU5AqXLiSB2JlEVbHCB_nINbQTWkjtoWxfqmvdOkIzwKtvdQ8FFb-crK9no9Bbbw +# to generate +APPLE_TEAM_ID=XC57P9SXDK +APPLE_KEY_ID=TB3V355G5Y APPLE_PRIVATE_KEY= -APPLE_KEY_ID= + AUTH0_ID=Aa9f3HJowauUrmBVY4iQzQJ7fYsaZDbK AUTH0_SECRET=_c0O9GkyRXkoWMQW7jNExnl6UoXN6O4oD3mg7NZ_uHVeAinCUtcTAkeQmcKXpZ4x diff --git a/_deploy/appleKey.p8 b/_deploy/appleKey.p8 new file mode 100644 index 0000000..4c686a8 --- /dev/null +++ b/_deploy/appleKey.p8 @@ -0,0 +1,6 @@ +-----BEGIN PRIVATE KEY----- +MIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQgL3WoWMr7zzqtZdF/ +wNEJ9+yMP2qNJV305gTdF+++hLOgCgYIKoZIzj0DAQehRANCAATqlUN+GE7/r8UQ +c93hRG9UxCtBcJEcgSGwYVPtZvA5igUBxY/6+RO/Tcnq9xT/6PZD0A82vMNSjoJ6 +/KyhaFLl +-----END PRIVATE KEY----- \ No newline at end of file diff --git a/_deploy/setupAppleId.mjs b/_deploy/setupAppleId.mjs index e8ceacb..51f9682 100644 --- a/_deploy/setupAppleId.mjs +++ b/_deploy/setupAppleId.mjs @@ -11,8 +11,17 @@ if (process.argv.includes("--help") || process.argv.includes("-h")) { Usage: node apple.mjs [--kid] [--iss] [--private_key] [--sub] [--expires_in] [--exp] - - node setupAppleId.mjs --kid YOUR_KEY_ID --iss YOUR_TEAM_ID --private_key "$(cat key.p8)" --sub YOUR_CLIENT_ID --expires_in 15778800 + APPLE_ID=com.mwhitnessing.sofia +APPLE_TEAM_ID=XC57P9SXDK +APPLE_KEY_ID=TB3V355G5Y +APPLE_KEY + +node setupAppleId.mjs --kid YOUR_KEY_ID --iss YOUR_TEAM_ID --private_key "$(cat key.p8)" --sub YOUR_CLIENT_ID --expires_in 15778800 +node setupAppleId.mjs --kid TB3V355G5Y --iss XC57P9SXDK --sub com.mwhitnessing.sofia --private_key "$(cat appleKey.p8)" + +>>Apple client secret generated. Valid until: Tue Oct 01 2024 00:05:43 GMT+0300 (Eastern European Summer Time) + +eyJhbGciOiJFUzI1NiIsImtpZCI6IlRCM1YzNTVHNVkifQ.eyJhdWQiOiJodHRwczovL2FwcGxlaWQuYXBwbGUuY29tIiwiaXNzIjoiWEM1N1A5U1hESyIsImlhdCI6MTcxMjE3ODM0MiwiZXhwIjoxNzI3NzMwMzQzLCJzdWIiOiJjb20ubXdoaXRuZXNzaW5nLnNvZmlhIn0.XceA0qUQi0tXg0GM_LkJkpNU5AqXLiSB2JlEVbHCB_nINbQTWkjtoWxfqmvdOkIzwKtvdQ8FFb-crK9no9Bbbw Options: diff --git a/components/availability/AvailabilityForm.js b/components/availability/AvailabilityForm.js index 868ccc1..a24f2af 100644 --- a/components/availability/AvailabilityForm.js +++ b/components/availability/AvailabilityForm.js @@ -87,27 +87,29 @@ export default function AvailabilityForm({ publisherId, existingItems, inline, o e.preventDefault(); try { const groupedTimeSlots = mergeCheckedTimeSlots(timeSlots); - + let avs = availabilities.filter(av => av.type !== "assignment"); // Determine if we need to delete and recreate, or just update - const shouldRecreate = availabilities.length !== groupedTimeSlots.length || availabilities.some(av => !av.id); - + let shouldRecreate = avs.length > 0 && avs.length !== groupedTimeSlots.length || avs.some(av => !av.id); + shouldRecreate = shouldRecreate || ( avs.length == 0 && availabilities.length > 0); + //create availability if we open a form with assignment without availability + if (shouldRecreate) { // Delete existing availabilities if they have an ID console.log("Recreating availabilities"); - await Promise.all(availabilities.filter(av => av.id).map(av => axiosInstance.delete(`${urls.apiUrl}${av.id}`))); + await Promise.all(avs.filter(av => av.id).map(av => axiosInstance.delete(`${urls.apiUrl}${av.id}`))); // Create new availabilities - const createdAvailabilities = await Promise.all(groupedTimeSlots.map(async group => { + avs = await Promise.all(groupedTimeSlots.map(async group => { const newAvailability = createAvailabilityFromGroup(group, publisher.id); const response = await axiosInstance.post(urls.apiUrl, newAvailability); return response.data; // Assuming the new availability is returned })); - setAvailabilities(createdAvailabilities); + setAvailabilities(avs); } else { // Update existing availabilities console.log("Updating existing availabilities"); - const updatedAvailabilities = await Promise.all(availabilities.map(async (availability, index) => { + avs = await Promise.all(avs.map(async (availability, index) => { const group = groupedTimeSlots[index]; const id = availability.id; const updatedAvailability = updateAvailabilityFromGroup(availability, group); @@ -121,7 +123,7 @@ export default function AvailabilityForm({ publisherId, existingItems, inline, o return updatedAvailability; })); - setAvailabilities(updatedAvailabilities); + setAvailabilities(avs); } handleCompletion({ updated: true }); @@ -228,7 +230,8 @@ export default function AvailabilityForm({ publisherId, existingItems, inline, o const handleDelete = async (e) => { e.preventDefault(); try { - const deletePromises = availabilities.map(async (availability) => { + let avs = availabilities.filter(av => av.type !== "assignment"); + const deletePromises = avs.map(async (availability) => { if (availability.id) { // console.log("deleting publisher id = ", router.query.id, "; url=" + urls.apiUrl + router.query.id); await axiosInstance.delete(urls.apiUrl + availability.id); diff --git a/components/calendar/avcalendar.tsx b/components/calendar/avcalendar.tsx index 577c53e..5403f1f 100644 --- a/components/calendar/avcalendar.tsx +++ b/components/calendar/avcalendar.tsx @@ -56,7 +56,14 @@ const AvCalendar = ({ publisherId, events, selectedDate }) => { // Update internal state when `events` prop changes useEffect(() => { - const updatedEvents = events.map(event => ({ + //if we have isBySystem - set type to assignment + let updatedEvents = events.map(event => { + if (event.isBySystem) { + event.type = "assignment"; + } + return event; + }); + updatedEvents = events.map(event => ({ ...event, date: new Date(event.startTime).setHours(0, 0, 0, 0), startTime: new Date(event.startTime), diff --git a/package.json b/package.json index 3858483..e8738af 100644 --- a/package.json +++ b/package.json @@ -109,4 +109,4 @@ "depcheck": "^1.4.7", "prisma": "^5.11.0" } -} \ No newline at end of file +} diff --git a/pages/_app.tsx b/pages/_app.tsx index e89920c..6538651 100644 --- a/pages/_app.tsx +++ b/pages/_app.tsx @@ -35,7 +35,7 @@ export default function App({ rel="stylesheet" /> - + diff --git a/pages/api/auth/[...nextauth].ts b/pages/api/auth/[...nextauth].ts index ce77c0b..61d1ee4 100644 --- a/pages/api/auth/[...nextauth].ts +++ b/pages/api/auth/[...nextauth].ts @@ -41,11 +41,15 @@ export const authOptions: NextAuthOptions = { } } }), - AzureADProvider({ - clientId: process.env.AZURE_AD_CLIENT_ID, - clientSecret: process.env.AZURE_AD_CLIENT_SECRET, - tenantId: process.env.AZURE_AD_TENANT_ID, + AppleProvider({ + clientId: process.env.APPLE_ID, + clientSecret: process.env.APPLE_SECRET }), + // AzureADProvider({ + // clientId: process.env.AZURE_AD_CLIENT_ID, + // clientSecret: process.env.AZURE_AD_CLIENT_SECRET, + // tenantId: process.env.AZURE_AD_TENANT_ID, + // }), CredentialsProvider({ // The name to display on the sign in form (e.g. 'Sign in with...') name: 'Credentials', @@ -87,11 +91,7 @@ export const authOptions: NextAuthOptions = { return null; } - }), - // AppleProvider({ - // clientId: process.env.APPLE_ID, - // clientSecret: process.env.APPLE_SECRET - // }) + }) /* EmailProvider({ server: { diff --git a/prisma/migrations/20240401231200_add_publisher_email_sbscription_options/migration.sql b/prisma/migrations/20240401231200_add_publisher_email_sbscription_options/migration.sql index 1e84220..e7f91bc 100644 --- a/prisma/migrations/20240401231200_add_publisher_email_sbscription_options/migration.sql +++ b/prisma/migrations/20240401231200_add_publisher_email_sbscription_options/migration.sql @@ -1,3 +1,3 @@ -- AlterTable -ALTER TABLE `publisher` ADD COLUMN `isSubscribedToCoverMe` BOOLEAN NOT NULL DEFAULT false, +ALTER TABLE `Publisher` ADD COLUMN `isSubscribedToCoverMe` BOOLEAN NOT NULL DEFAULT false, ADD COLUMN `isSubscribedToReminders` BOOLEAN NOT NULL DEFAULT false;