import { Button, FormContainer, Input, Notification, Select, toast } from '@/components/ui' import { Field, FieldArray, Form, Formik, FieldProps } from 'formik' import { FaMinus, FaPlus, FaTimes, FaSave } from 'react-icons/fa' import { SelectBoxOption } from '@/types/shared' import { chartSeriesTypeOptions, columnSummaryTypeListOptions } from '../admin/listForm/edit/options' import { ChartSeriesDto } from '@/proxy/admin/charts/models' import { useLocalization } from '@/utils/hooks/useLocalization' import { useStoreState } from '@/store/store' import { object, array, string } from 'yup' import { SummaryTypeEnum } from '@/proxy/form/models' import { useState, useEffect } from 'react' interface ChartDrawerProps { open: boolean onClose: () => void initialSeries: ChartSeriesDto[] fieldList: SelectBoxOption[] onSave: (series: ChartSeriesDto[]) => void onPreviewChange: (series: ChartSeriesDto[]) => void } const ChartDrawer = ({ open, onClose, initialSeries, fieldList, onSave, onPreviewChange, }: ChartDrawerProps) => { const { translate } = useLocalization() const { userName } = useStoreState((s) => s.auth.user) const [selectedSeriesIndex, setSelectedSeriesIndex] = useState(-1) const schema = object().shape({ series: array().of( object().shape({ name: string().required(translate('::App.Platform.ChartDrawer.NameRequired')), argumentField: string().required( translate('::App.Platform.ChartDrawer.ArgumentFieldRequired'), ), valueField: string().required(translate('::App.Platform.ChartDrawer.ValueFieldRequired')), summaryType: string().required(translate('::App.Platform.ChartDrawer.SummaryTypeRequired')), }), ), }) const newSeriesValue = () => { return { index: -1, type: 'line', name: '', argumentField: '', valueField: '', summaryType: SummaryTypeEnum.Sum, axis: '', barOverlapGroup: '', barPadding: 0, barWidth: 0, color: '', cornerRadius: 0, dashStyle: 'solid', ignoreEmptyPoints: false, pane: '', rangeValue1Field: '', rangeValue2Field: '', selectionMode: 'none', showInLegend: true, visible: true, width: 2, label: { visible: true, backgroundColor: '#f05b41', customizeText: '', format: 'decimal', font: { color: '#FFFFFF', family: '"Segoe UI", "Helvetica Neue", "Trebuchet MS", Verdana, sans-serif', size: 12, weight: 400, }, }, userId: userName ?? '', } } if (!open) return null return ( <> {/* Drawer */}
0 ? initialSeries : [newSeriesValue()], }} validationSchema={schema} onSubmit={async (values, { setSubmitting }) => { try { await onSave(values.series) toast.push( {translate('::App.Platform.ChartDrawer.ChartSaved')} , { placement: 'top-end', }, ) onClose() } catch (error: any) { toast.push( {translate('::App.Platform.ChartDrawer.Error')} {error} , { placement: 'top-end' }, ) } finally { setSubmitting(false) } }} > {({ setFieldValue, values, isSubmitting }) => { // Preview'ı her değişiklikte otomatik güncelle useEffect(() => { const validSeries = values.series.filter( (s) => s.argumentField && s.valueField && s.summaryType, ) if (validSeries.length > 0) { onPreviewChange(validSeries) } }, [values.series]) return (
{/* Header */}

📊 {translate('::App.Platform.ChartDrawer.ChartSeries')}

{/* Add Series Button */}
{/* Scrollable Content */}
{({ remove }) => (
{values.series.map((series, index) => (
{/* Header */}
{translate('::App.Platform.ChartDrawer.Series')} #{index + 1}
{/* Chart Type Selector */}
{({ field, form }: FieldProps) => (
{selectedSeriesIndex === index && (
{chartSeriesTypeOptions.map((chartType) => ( ))}
)}
)}
{/* Name */}
{/* Argument Field */}
{({ field, form }: FieldProps) => ( option.value === field.value, )} onChange={(option) => { form.setFieldValue(field.name, option?.value) }} placeholder={translate( '::App.Platform.ChartDrawer.SelectField', )} /> )}
{/* Summary Type */}
{({ field, form }: FieldProps) => (