Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Require confirmation to delete WebVTT #4232

Merged
merged 1 commit into from
Oct 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 39 additions & 16 deletions app/assets/js/components/Work/Tabs/Structure/WebVTTModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ function WorkTabsStructureWebVTTModal({ isActive }) {
const [parseErrors, setParseErrors] = React.useState();
const workState = useWorkState();
const [webVttValue, setWebVttValue] = React.useState("");
const [confirmDelete, setConfirmDelete] = React.useState(false);
const params = useParams();
const workId = params.id;

Expand All @@ -34,7 +35,7 @@ function WorkTabsStructureWebVTTModal({ isActive }) {
if (graphQLErrors?.length > 0) {
errorStrings = graphQLErrors.map(
({ message, details }) =>
`${message}: ${details && details.title ? details.title : ""}`
`${message}: ${details && details.title ? details.title : ""}`,
);
}
toastWrapper("is-danger", errorStrings.join(" \n "));
Expand Down Expand Up @@ -65,6 +66,7 @@ function WorkTabsStructureWebVTTModal({ isActive }) {
dispatch({ type: "toggleWebVttModal", fileSetId: null });
setParseErrors(null);
setWebVttValue("");
setConfirmDelete(false);
};

const handleSubmit = (structuralMetadata) => {
Expand All @@ -76,6 +78,12 @@ function WorkTabsStructureWebVTTModal({ isActive }) {
});
};

const handleDelete = () => {
setConfirmDelete(true);
setParseErrors("Are you sure you want to delete this WebVTT structure?");
setWebVttValue("");
};

return (
<div
className={classNames(["modal"], {
Expand All @@ -95,6 +103,12 @@ function WorkTabsStructureWebVTTModal({ isActive }) {
</header>

<section className="modal-card-body">
{confirmDelete && (
<Notification isDanger>
Are you sure you want to delete this WebVTT structure?
</Notification>
)}

{webVttValue?.trim().length > 0 &&
(parseErrors ? (
<Notification isDanger>{parseErrors.message}</Notification>
Expand All @@ -107,34 +121,43 @@ function WorkTabsStructureWebVTTModal({ isActive }) {
placeholder="Enter WebVTT text here"
ref={textAreaRef}
rows="10"
style={{ whiteSpace: "pre-wrap" }}
style={{
whiteSpace: "pre-wrap",
display: confirmDelete ? "none" : "block",
}}
value={webVttValue}
/>
</section>
<footer className="modal-card-foot buttons is-justify-content-space-between">
{webVttValue?.trim().length > 0 && (
{webVttValue?.trim().length > 0 && !confirmDelete && (
<Button
isText
onClick={() => handleSubmit({})}
onClick={() => handleDelete()}
css={{ backgroundColor: "transparent" }}
>
Delete WebVTT
</Button>
)}
<div className="is-flex is-justify-content-flex-end is-flex-grow-1">
<Button onClick={handleClose}>Cancel</Button>
<Button
isPrimary
onClick={() =>
handleSubmit({
type: "WEBVTT",
value: webVttValue,
})
}
disabled={parseErrors}
>
Submit
</Button>
{confirmDelete ? (
<Button isPrimary onClick={() => handleSubmit({})}>
Yes, delete
</Button>
) : (
<Button
isPrimary
onClick={() =>
handleSubmit({
type: "WEBVTT",
value: webVttValue,
})
}
disabled={parseErrors}
>
Submit
</Button>
)}
</div>
</footer>
</div>
Expand Down
Loading