mirror of
https://github.com/Sonny93/my-links.git
synced 2025-12-10 07:25:35 +00:00
feat: add delete collection form and controller method
This commit is contained in:
41
inertia/pages/collections/delete.tsx
Normal file
41
inertia/pages/collections/delete.tsx
Normal file
@@ -0,0 +1,41 @@
|
||||
import type Collection from '#models/collection';
|
||||
import { useForm } from '@inertiajs/react';
|
||||
import { route } from '@izzyjs/route/client';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import FormCollection, {
|
||||
FormCollectionData,
|
||||
} from '~/components/form/form_collection';
|
||||
|
||||
export default function DeleteCollectionPage({
|
||||
collection,
|
||||
}: {
|
||||
collection: Collection;
|
||||
}) {
|
||||
const { t } = useTranslation('common');
|
||||
const { data, setData, submit, processing, errors } =
|
||||
useForm<FormCollectionData>({
|
||||
name: collection.name,
|
||||
description: collection.description,
|
||||
visibility: collection.visibility,
|
||||
});
|
||||
|
||||
const handleSubmit = () => {
|
||||
const { method, url } = route('collection.delete', {
|
||||
params: { id: collection.id },
|
||||
});
|
||||
submit(method, url);
|
||||
};
|
||||
|
||||
return (
|
||||
<FormCollection
|
||||
title={t('collection.delete')}
|
||||
canSubmit={!processing}
|
||||
data={data}
|
||||
setData={setData}
|
||||
handleSubmit={handleSubmit}
|
||||
errors={errors as any}
|
||||
disableInputs={true}
|
||||
submitBtnDanger
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -2,6 +2,7 @@ import type Collection from '#models/collection';
|
||||
import { useForm } from '@inertiajs/react';
|
||||
import { route } from '@izzyjs/route/client';
|
||||
import { useMemo } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import FormCollection, {
|
||||
FormCollectionData,
|
||||
} from '~/components/form/form_collection';
|
||||
@@ -11,6 +12,7 @@ export default function EditCollectionPage({
|
||||
}: {
|
||||
collection: Collection;
|
||||
}) {
|
||||
const { t } = useTranslation('common');
|
||||
const { data, setData, submit, processing, errors } =
|
||||
useForm<FormCollectionData>({
|
||||
name: collection.name,
|
||||
@@ -35,7 +37,7 @@ export default function EditCollectionPage({
|
||||
|
||||
return (
|
||||
<FormCollection
|
||||
title="Edit a collection"
|
||||
title={t('collection.edit')}
|
||||
canSubmit={canSubmit}
|
||||
data={data}
|
||||
setData={setData}
|
||||
|
||||
Reference in New Issue
Block a user