Skip to content

Commit

Permalink
fix publication configuration bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
ousamazemzami committed Dec 13, 2024
1 parent cf844f5 commit 15b77bb
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 13 deletions.
1 change: 0 additions & 1 deletion server/controllers/activity.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable no-console */
import type { JSONSchemaType } from 'ajv';
import type { NextFunction, Request, Response } from 'express';
import { IsNull } from 'typeorm';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable no-console */
import Link from 'next/link';
import { useRouter } from 'next/router';
import React, { useEffect } from 'react';
Expand Down Expand Up @@ -60,7 +59,6 @@ export default function ActivityCard({
setAnchorEl(null);
};
const handleUpdate = () => {
console.log(activity);
if (activity.type === 5) {
router.push(`/admin/newportal/contenulibre/edit/1/${activity.id}`);
}
Expand Down
1 change: 0 additions & 1 deletion src/contexts/activityContext.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable no-console */
import { useRouter } from 'next/router';
import React from 'react';
import { useQueryClient } from 'react-query';
Expand Down
16 changes: 7 additions & 9 deletions src/pages/admin/newportal/publier/prepublish/edit/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ const ModifPrepublish = () => {
const villagesToAdd = selectedVillages.filter((villageId) => !publishedVillageIds.includes(villageId));
const villagesToDelete = publishedVillageIds.filter((villageId) => !selectedVillages.includes(villageId));

if (Number(selectedPhase) !== childrenActivities[0].phase) {
if (childrenActivities.length > 0 && Number(selectedPhase) !== childrenActivities[0].phase) {
await Promise.all(
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
Expand Down Expand Up @@ -201,19 +201,17 @@ const ModifPrepublish = () => {
const isModificationDisabled = () => {
if (isLoading) return true;

const publishedVillageIds = childrenActivities.map((activity: Activity) => activity.villageId).filter((id: number) => id !== undefined); // Exclude undefined IDs

const hasPublishedVillages = publishedVillageIds.length > 0;
const hasSelectedVillages = selectedVillages.length > 0;

// Check if published and selected have the same numbers
const areVillagesTheSame =
hasPublishedVillages &&
hasSelectedVillages &&
publishedVillageIds.length === selectedVillages.length &&
publishedVillageIds.every((id: number) => selectedVillages.includes(id));
publishedVillageIds.length === selectedVillages.length && publishedVillageIds.every((id: number) => selectedVillages.includes(id));

const phaseChanged = childrenActivities.length > 0 && childrenActivities[0]?.phase !== Number(selectedPhase);

const noChangesMade = areVillagesTheSame && !phaseChanged;

return (selectedVillages.length < 1 && publishedVillageIds.length === 0) || areVillagesTheSame;
return (!hasSelectedVillages && !hasPublishedVillages) || noChangesMade;
};

return (
Expand Down

0 comments on commit 15b77bb

Please sign in to comment.