145 lines
4.6 KiB
TypeScript
145 lines
4.6 KiB
TypeScript
import { mdiChartTimelineVariant } from '@mdi/js';
|
|
import Head from 'next/head';
|
|
import React, { ReactElement } from 'react';
|
|
|
|
import CardBox from '../../components/CardBox';
|
|
import LayoutAuthenticated from '../../layouts/Authenticated';
|
|
import SectionMain from '../../components/SectionMain';
|
|
import SectionTitleLineWithButton from '../../components/SectionTitleLineWithButton';
|
|
import { getPageTitle } from '../../config';
|
|
|
|
import { Field, Form, Formik } from 'formik';
|
|
import FormField from '../../components/FormField';
|
|
import BaseDivider from '../../components/BaseDivider';
|
|
import BaseButtons from '../../components/BaseButtons';
|
|
import BaseButton from '../../components/BaseButton';
|
|
import { SelectField } from '../../components/SelectField';
|
|
|
|
import { update, fetch } from '../../stores/asset_variants/asset_variantsSlice';
|
|
import { useAppDispatch } from '../../stores/hooks';
|
|
import { useRouter } from 'next/router';
|
|
import { useEditPageSync } from '../../hooks/useEditPageSync';
|
|
import type { AssetVariant } from '../../types/entities';
|
|
|
|
const initVals = {
|
|
asset: null as AssetVariant['asset'] | null,
|
|
variant_type: '',
|
|
cdn_url: '',
|
|
width_px: '',
|
|
height_px: '',
|
|
size_mb: '',
|
|
};
|
|
|
|
const EditAsset_variantsPage = () => {
|
|
const router = useRouter();
|
|
const dispatch = useAppDispatch();
|
|
|
|
const { values: initialValues, id } = useEditPageSync({
|
|
entitySelector: (state) => state.asset_variants.asset_variants,
|
|
fetchAction: fetch,
|
|
initialValues: initVals,
|
|
});
|
|
|
|
const handleSubmit = async (data: typeof initVals) => {
|
|
if (id) {
|
|
await dispatch(
|
|
update({ id, data: data as unknown as Partial<AssetVariant> }),
|
|
);
|
|
await router.push('/asset_variants/asset_variants-list');
|
|
}
|
|
};
|
|
|
|
return (
|
|
<>
|
|
<Head>
|
|
<title>{getPageTitle('Edit asset_variants')}</title>
|
|
</Head>
|
|
<SectionMain>
|
|
<SectionTitleLineWithButton
|
|
icon={mdiChartTimelineVariant}
|
|
title='Edit asset_variants'
|
|
main
|
|
>
|
|
{''}
|
|
</SectionTitleLineWithButton>
|
|
<CardBox>
|
|
<Formik
|
|
enableReinitialize
|
|
initialValues={initialValues}
|
|
onSubmit={(values) => handleSubmit(values)}
|
|
>
|
|
<Form>
|
|
<FormField label='Asset' labelFor='asset'>
|
|
<Field
|
|
name='asset'
|
|
id='asset'
|
|
component={SelectField}
|
|
options={initialValues.asset}
|
|
itemRef='assets'
|
|
showField='name'
|
|
/>
|
|
</FormField>
|
|
|
|
<FormField label='Variant Type' labelFor='variant_type'>
|
|
<Field name='variant_type' id='variant_type' component='select'>
|
|
<option value='thumbnail'>thumbnail</option>
|
|
<option value='preview'>preview</option>
|
|
<option value='webp'>webp</option>
|
|
<option value='mp4_low'>mp4_low</option>
|
|
<option value='mp4_high'>mp4_high</option>
|
|
<option value='original'>original</option>
|
|
</Field>
|
|
</FormField>
|
|
|
|
<FormField label='CDN URL'>
|
|
<Field name='cdn_url' placeholder='CDN URL' />
|
|
</FormField>
|
|
|
|
<FormField label='Width (px)'>
|
|
<Field type='number' name='width_px' placeholder='Width (px)' />
|
|
</FormField>
|
|
|
|
<FormField label='Height (px)'>
|
|
<Field
|
|
type='number'
|
|
name='height_px'
|
|
placeholder='Height (px)'
|
|
/>
|
|
</FormField>
|
|
|
|
<FormField label='Size (MB)'>
|
|
<Field type='number' name='size_mb' placeholder='Size (MB)' />
|
|
</FormField>
|
|
|
|
<BaseDivider />
|
|
<BaseButtons>
|
|
<BaseButton type='submit' color='info' label='Submit' />
|
|
<BaseButton type='reset' color='info' outline label='Reset' />
|
|
<BaseButton
|
|
type='reset'
|
|
color='danger'
|
|
outline
|
|
label='Cancel'
|
|
onClick={() =>
|
|
router.push('/asset_variants/asset_variants-list')
|
|
}
|
|
/>
|
|
</BaseButtons>
|
|
</Form>
|
|
</Formik>
|
|
</CardBox>
|
|
</SectionMain>
|
|
</>
|
|
);
|
|
};
|
|
|
|
EditAsset_variantsPage.getLayout = function getLayout(page: ReactElement) {
|
|
return (
|
|
<LayoutAuthenticated permission='UPDATE_ASSET_VARIANTS'>
|
|
{page}
|
|
</LayoutAuthenticated>
|
|
);
|
|
};
|
|
|
|
export default EditAsset_variantsPage;
|