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

✨ Remove the selected filter macro instead of the last one in the list #221

Merged
merged 1 commit into from
Oct 18, 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
22 changes: 11 additions & 11 deletions app/events/filters/macros/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,19 @@ import { ActionButton, LinkButton } from '@/common/buttons'
import { PlusIcon, TrashIcon } from '@heroicons/react/24/solid'
import { ConfirmationModal } from '@/common/modals/confirmation'
import { useState } from 'react'
import { EmptyDataset } from '@/common/feeds/EmptyFeed'

const dateFormatter = new Intl.DateTimeFormat('en-US', {
dateStyle: 'medium',
timeStyle: 'short',
})

export default function EventFiltersMacrosListPage() {
const [isOpen, setIsOpen] = useState(false)
const [removingMacro, setRemovingMacro] = useState('')
const { data: macroList, isFetching, error } = useFilterMacroList()
const {
mutateAsync: removeMacro,
error: removeMacroError,
isLoading: isRemovingMacro,
isLoading: removingMacroMacro,
} = useFilterMacroRemoveMutation()

useTitle('Moderation Filter Macros')
Expand All @@ -36,7 +35,7 @@ export default function EventFiltersMacrosListPage() {
return <Loading />
}

const confirmButtonText = isRemovingMacro ? 'Removing...' : 'Yes, Remove'
const confirmButtonText = removingMacroMacro ? 'Removing...' : 'Yes, Remove'
const listItems = Object.entries(macroList)

return (
Expand Down Expand Up @@ -65,25 +64,26 @@ export default function EventFiltersMacrosListPage() {
appearance="outlined"
size="sm"
type="button"
onClick={() => setIsOpen(true)}
onClick={() => setRemovingMacro(name)}
>
<TrashIcon className="h-3 w-3" />
</ActionButton>

<ConfirmationModal
onConfirm={() => {
removeMacro(name).then(() => setIsOpen(false))
removeMacro(removingMacro).then(() => setRemovingMacro(''))
}}
isOpen={isOpen}
setIsOpen={setIsOpen}
isOpen={removingMacro === name}
setIsOpen={(val) => setRemovingMacro(val ? name : '')}
confirmButtonText={confirmButtonText}
confirmButtonDisabled={isRemovingMacro}
confirmButtonDisabled={removingMacroMacro}
error={removeMacroError?.['message']}
title={`Remove Filter Macro?`}
description={
<>
You can always recreate your macro from the event filter
panel
You{"'"}re about to remove the filter macro{' '}
{`"${removingMacro}"`}. You can always recreate your macro
from the event filter panel.
</>
}
/>
Expand Down
Loading