diff --git a/src/app/(proper_react)/(redesign)/(authenticated)/user/(dashboard)/dashboard/fix/data-broker-profiles/removal-under-maintenance/DataBrokerRemovalMaintenance.tsx b/src/app/(proper_react)/(redesign)/(authenticated)/user/(dashboard)/dashboard/fix/data-broker-profiles/removal-under-maintenance/DataBrokerRemovalMaintenance.tsx index f10c7294850..e5fc17bd8c1 100644 --- a/src/app/(proper_react)/(redesign)/(authenticated)/user/(dashboard)/dashboard/fix/data-broker-profiles/removal-under-maintenance/DataBrokerRemovalMaintenance.tsx +++ b/src/app/(proper_react)/(redesign)/(authenticated)/user/(dashboard)/dashboard/fix/data-broker-profiles/removal-under-maintenance/DataBrokerRemovalMaintenance.tsx @@ -15,6 +15,7 @@ import { ClockIcon } from "../../../../../../../../../components/server/Icons"; export type DataBrokerRemovalMaintenanceProps = { scanResult: OnerepScanResultRow; isPremiumUser: boolean; + onMarkAsResolved?: () => void; }; export const DataBrokerRemovalMaintenance = ( @@ -86,7 +87,6 @@ export const DataBrokerRemovalMaintenance = ( ))}
- {/* TODO: Add functionality to these buttons */} { - if (props.data === null) { - console.error("No scan data"); - } const l10n = useL10n(); - const testScanItem = props.data; - const firstScan = testScanItem[0]; - const [detailedRemovalGuide, setDetailedRemovalGuide] = useState(false); + const [firstScanResultNotResolved, setFirstScanResultNotResolved] = useState( + props.data.results[0], + ); + const nextGuidedStep = getNextGuidedStep( + props.stepDeterminationData, + "DataBrokerManualRemoval", + ); + + async function handleManualRemovalChange() { + const response = await fetch( + `/api/v1/user/scan-result/${firstScanResultNotResolved.onerep_scan_result_id}/resolution`, + { + method: "POST", + credentials: "same-origin", + }, + ); + + if (!response.ok) { + console.error( + "Could not update next data broker with removal under maintenance status.", + ); + return; + } + // Mannualy move to next step in response works + firstScanResultNotResolved.manually_resolved = true; + + // Find the next unresolved scan result + const nextScanResultNotResolved = props.data.results.find( + (scanResult) => !scanResult.manually_resolved, + ); + + // Update the state to the next unresolved scan result + if (nextScanResultNotResolved) { + setFirstScanResultNotResolved(nextScanResultNotResolved); + } + + // Move to the next step + else { + window.location.href = nextGuidedStep.href; + } + } const dataBrokerInformation = (

@@ -42,25 +78,30 @@ export const RemovalUnderMaintenanceView = (props: Props) => { elems: { link_to_data_broker: ( ), }, vars: { - data_broker_name: firstScan.data_broker, + data_broker_name: firstScanResultNotResolved.data_broker, }, })}

{ + handleManualRemovalChange().catch((error) => { + console.error("Error during manual removal change:", error); + }); + }} /> -
{l10n.getString( @@ -217,7 +258,7 @@ export const RemovalUnderMaintenanceView = (props: Props) => { return ( ); diff --git a/src/app/functions/server/getRelevantGuidedSteps.ts b/src/app/functions/server/getRelevantGuidedSteps.ts index 2dc954426e5..a4f53d0652f 100644 --- a/src/app/functions/server/getRelevantGuidedSteps.ts +++ b/src/app/functions/server/getRelevantGuidedSteps.ts @@ -203,7 +203,6 @@ export function hasCompletedStepSection( if (section === "DataBrokerManualRemoval") { return hasCompletedStep(data, "DataBrokerManualRemoval"); } - /* c8 ignore next 5 */ // I believe this *is* covered by unit tests, but for some reason, // since the upgrade to Node 20.10, it doesn't get marked as covered anymore: @@ -245,8 +244,15 @@ export function hasCompletedStep( data: StepDeterminationData, stepId: StepLink["id"], ): boolean { - // TODO: - // if (stepId === "DataBrokerManualRemoval") { add business logic here } + if (stepId === "DataBrokerManualRemoval") { + const hasResolvedAllScanResults = + data.latestScanData?.results + ?.filter( + (scanResult) => scanResult.status === "removal_under_maintenance", + ) + .every((scanResult) => scanResult.manually_resolved) ?? false; + return hasResolvedAllScanResults; + } if (stepId === "Scan") { const hasRunScan =