mirror of
https://github.com/Sonny93/my-links.git
synced 2025-12-10 07:25:35 +00:00
feat: use new form layout for collection/delete
This commit is contained in:
@@ -96,7 +96,7 @@ export default class CollectionsController {
|
|||||||
collectionId,
|
collectionId,
|
||||||
auth.user!.id
|
auth.user!.id
|
||||||
);
|
);
|
||||||
return inertia.render('collections/delete', {
|
return inertia.render('mantine/collections/delete', {
|
||||||
collection,
|
collection,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,10 @@ import { Box, Group, SegmentedControl, Text, TextInput } from '@mantine/core';
|
|||||||
import { FormEvent } from 'react';
|
import { FormEvent } from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import BackToDashboard from '~/components/common/navigation/back_to_dashboard';
|
import BackToDashboard from '~/components/common/navigation/back_to_dashboard';
|
||||||
import { MantineFormLayout } from '~/mantine/layouts/mantine_form_layout';
|
import {
|
||||||
|
FormLayoutProps,
|
||||||
|
MantineFormLayout,
|
||||||
|
} from '~/mantine/layouts/mantine_form_layout';
|
||||||
import { Collection } from '~/types/app';
|
import { Collection } from '~/types/app';
|
||||||
|
|
||||||
export type FormCollectionData = {
|
export type FormCollectionData = {
|
||||||
@@ -13,30 +16,22 @@ export type FormCollectionData = {
|
|||||||
nextId?: Collection['id'];
|
nextId?: Collection['id'];
|
||||||
};
|
};
|
||||||
|
|
||||||
interface FormCollectionProps {
|
interface FormCollectionProps extends FormLayoutProps {
|
||||||
title: string;
|
|
||||||
canSubmit: boolean;
|
|
||||||
disableHomeLink?: boolean;
|
|
||||||
data: FormCollectionData;
|
data: FormCollectionData;
|
||||||
errors?: Record<string, Array<string>>;
|
errors?: Record<string, Array<string>>;
|
||||||
disableInputs?: boolean;
|
disableInputs?: boolean;
|
||||||
submitBtnDanger?: boolean;
|
|
||||||
|
|
||||||
setData: (name: string, value: any) => void;
|
setData: (name: string, value: any) => void;
|
||||||
handleSubmit: () => void;
|
handleSubmit: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function MantineFormCollection({
|
export default function MantineFormCollection({
|
||||||
title,
|
|
||||||
canSubmit,
|
|
||||||
disableHomeLink,
|
|
||||||
data,
|
data,
|
||||||
errors,
|
errors,
|
||||||
disableInputs = false,
|
disableInputs = false,
|
||||||
submitBtnDanger = false,
|
|
||||||
|
|
||||||
setData,
|
setData,
|
||||||
handleSubmit,
|
handleSubmit,
|
||||||
|
...props
|
||||||
}: FormCollectionProps) {
|
}: FormCollectionProps) {
|
||||||
const { t } = useTranslation('common');
|
const { t } = useTranslation('common');
|
||||||
|
|
||||||
@@ -46,20 +41,14 @@ export default function MantineFormCollection({
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<MantineFormLayout
|
<MantineFormLayout handleSubmit={onSubmit} {...props}>
|
||||||
title={title}
|
|
||||||
handleSubmit={onSubmit}
|
|
||||||
canSubmit={canSubmit}
|
|
||||||
disableHomeLink={disableHomeLink}
|
|
||||||
submitBtnDanger={submitBtnDanger}
|
|
||||||
>
|
|
||||||
<BackToDashboard>
|
<BackToDashboard>
|
||||||
<TextInput
|
<TextInput
|
||||||
label={t('form.name')}
|
label={t('form.name')}
|
||||||
placeholder={t('form.name')}
|
placeholder={t('form.name')}
|
||||||
onChange={({ target }) => setData('name', target.value)}
|
onChange={({ target }) => setData('name', target.value)}
|
||||||
value={data.name}
|
value={data.name}
|
||||||
disabled={disableInputs}
|
readOnly={disableInputs}
|
||||||
error={errors?.name}
|
error={errors?.name}
|
||||||
mt="md"
|
mt="md"
|
||||||
autoFocus
|
autoFocus
|
||||||
@@ -70,7 +59,7 @@ export default function MantineFormCollection({
|
|||||||
placeholder={t('form.description')}
|
placeholder={t('form.description')}
|
||||||
onChange={({ target }) => setData('description', target.value)}
|
onChange={({ target }) => setData('description', target.value)}
|
||||||
value={data.description ?? undefined}
|
value={data.description ?? undefined}
|
||||||
disabled={disableInputs}
|
readOnly={disableInputs}
|
||||||
error={errors?.description}
|
error={errors?.description}
|
||||||
mt="md"
|
mt="md"
|
||||||
/>
|
/>
|
||||||
@@ -87,6 +76,7 @@ export default function MantineFormCollection({
|
|||||||
onChange={(value) => setData('visibility', value as Visibility)}
|
onChange={(value) => setData('visibility', value as Visibility)}
|
||||||
value={data.visibility}
|
value={data.visibility}
|
||||||
style={{ minWidth: 'fit-content' }}
|
style={{ minWidth: 'fit-content' }}
|
||||||
|
readOnly={disableInputs}
|
||||||
/>
|
/>
|
||||||
{data.visibility === Visibility.PUBLIC && (
|
{data.visibility === Visibility.PUBLIC && (
|
||||||
<Text c="dimmed" size="sm">
|
<Text c="dimmed" size="sm">
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import i18n from '~/i18n';
|
|||||||
import { appendCollectionId } from '~/lib/navigation';
|
import { appendCollectionId } from '~/lib/navigation';
|
||||||
import BaseLayout from '~/mantine/layouts/_mantine_base_layout';
|
import BaseLayout from '~/mantine/layouts/_mantine_base_layout';
|
||||||
|
|
||||||
interface FormLayoutProps extends PropsWithChildren {
|
export interface FormLayoutProps extends PropsWithChildren {
|
||||||
title: string;
|
title: string;
|
||||||
|
|
||||||
canSubmit: boolean;
|
canSubmit: boolean;
|
||||||
@@ -26,7 +26,7 @@ function MantineFormLayout({
|
|||||||
|
|
||||||
canSubmit,
|
canSubmit,
|
||||||
handleSubmit,
|
handleSubmit,
|
||||||
textSubmitButton = i18n.t('common:form.create'),
|
textSubmitButton = i18n.t('common:form.confirm'),
|
||||||
|
|
||||||
disableHomeLink = false,
|
disableHomeLink = false,
|
||||||
submitBtnDanger = false,
|
submitBtnDanger = false,
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ export default function CreateCollectionPage({
|
|||||||
return (
|
return (
|
||||||
<MantineFormCollection
|
<MantineFormCollection
|
||||||
title={t('collection.create')}
|
title={t('collection.create')}
|
||||||
|
textSubmitButton={t('form.create')}
|
||||||
canSubmit={!isFormDisabled}
|
canSubmit={!isFormDisabled}
|
||||||
disableHomeLink={disableHomeLink}
|
disableHomeLink={disableHomeLink}
|
||||||
data={data}
|
data={data}
|
||||||
|
|||||||
42
inertia/pages/mantine/collections/delete.tsx
Normal file
42
inertia/pages/mantine/collections/delete.tsx
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
import { useForm } from '@inertiajs/react';
|
||||||
|
import { route } from '@izzyjs/route/client';
|
||||||
|
import { useTranslation } from 'react-i18next';
|
||||||
|
import MantineFormCollection, {
|
||||||
|
FormCollectionData,
|
||||||
|
} from '~/mantine/components/form/mantine_form_collection';
|
||||||
|
import { Collection } from '~/types/app';
|
||||||
|
|
||||||
|
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.toString() },
|
||||||
|
});
|
||||||
|
submit(method, url);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<MantineFormCollection
|
||||||
|
title={t('collection.delete')}
|
||||||
|
textSubmitButton={t('form.delete')}
|
||||||
|
canSubmit={!processing}
|
||||||
|
data={data}
|
||||||
|
setData={setData}
|
||||||
|
handleSubmit={handleSubmit}
|
||||||
|
errors={errors as any}
|
||||||
|
disableInputs
|
||||||
|
submitBtnDanger
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -39,6 +39,7 @@ export default function EditCollectionPage({
|
|||||||
return (
|
return (
|
||||||
<MantineFormCollection
|
<MantineFormCollection
|
||||||
title={t('collection.edit')}
|
title={t('collection.edit')}
|
||||||
|
textSubmitButton={t('form.update')}
|
||||||
canSubmit={canSubmit}
|
canSubmit={canSubmit}
|
||||||
data={data}
|
data={data}
|
||||||
setData={setData}
|
setData={setData}
|
||||||
|
|||||||
Reference in New Issue
Block a user