Skip to content

Commit

Permalink
feat: reset after maintenance type value changed
Browse files Browse the repository at this point in the history
  • Loading branch information
valeriocomo committed Dec 12, 2024
1 parent a4801e3 commit 24fab50
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion src/app/components/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import PubliccodeYmlLanguages from "./PubliccodeYmlLanguages";

import { Col, Container, notify, Row } from "design-react-kit";
import { set } from "lodash";
import { useCallback, useState } from "react";
import { useCallback, useEffect, useState } from "react";
import { useTranslation } from "react-i18next";
import YAML from "yaml";
import licenses from "../../generated/licenses.json";
Expand Down Expand Up @@ -168,6 +168,33 @@ export default function Editor() {
storage: window?.localStorage, // default window.sessionStorage
exclude: [],
});

const resetMaintenance = useCallback((value: Partial<PublicCode>) => {
const maintenanceType = (value as PublicCode).maintenance.type;

if (maintenanceType === "none") {
setValue('maintenance.contacts', [])
setValue('maintenance.contractors', [])
}

if (maintenanceType === "community" || maintenanceType === "internal") {
setValue('maintenance.contractors', [])
}

if (maintenanceType === "contract") {
setValue('maintenance.contacts', [])
}
}, [setValue])

useEffect(() => {
const subscription = watch((value, { name }) => {
if (name === 'maintenance.type') {
resetMaintenance(value as PublicCode);
}
}
)
return () => subscription.unsubscribe()
}, [watch, resetMaintenance])
//#endregion

//#region form action handlers
Expand Down

0 comments on commit 24fab50

Please sign in to comment.