diff --git a/next/web/src/App/Admin/Tickets/Ticket/components/CustomFields.tsx b/next/web/src/App/Admin/Tickets/Ticket/components/CustomFields.tsx index 0493c2d81..e40495bb3 100644 --- a/next/web/src/App/Admin/Tickets/Ticket/components/CustomFields.tsx +++ b/next/web/src/App/Admin/Tickets/Ticket/components/CustomFields.tsx @@ -1,4 +1,4 @@ -import { JSXElementConstructor, ReactNode, useMemo, useState } from 'react'; +import { JSXElementConstructor, useMemo, useState } from 'react'; import { isEmpty } from 'lodash-es'; import Handlebars from 'handlebars'; import DOMPurify from 'dompurify'; @@ -74,11 +74,10 @@ export function CustomFields({ return null; } - const displayValue = tempValues[field.id] ?? values[field.id]?.value; const contentNode = ( setTempValues({ ...tempValues, [field.id]: value })} @@ -88,30 +87,26 @@ export function CustomFields({ let previewNode; const { previewTemplate, id } = field; const value = values[id]?.value; - const defaultContent = renderDefaultContent(field, value, values[id]?.files); - const previewValue = getPreviewValue(field, value); - const useDefaultContent = !previewTemplate && isGameField(field) && defaultContent; const DEFAULT_CONTENT_PLACEHOLDER = '#DEFAULT#'; if (previewTemplate) { const showPreviewAnyway = previewTemplate.startsWith('!'); if (showPreviewAnyway || value !== undefined) { const template = showPreviewAnyway ? previewTemplate.slice(1) : previewTemplate; - const templateWithoutDefault = template - .replace(RegExp(`^${DEFAULT_CONTENT_PLACEHOLDER}`), '') - .replace(RegExp(`${DEFAULT_CONTENT_PLACEHOLDER}$`), ''); previewNode = ( (
Render preview template error: {error.message}
)} > - {template.startsWith(DEFAULT_CONTENT_PLACEHOLDER) && defaultContent} + {/* {template.startsWith(DEFAULT_CONTENT_PLACEHOLDER) && defaultContent} */} - {template.endsWith(DEFAULT_CONTENT_PLACEHOLDER) && defaultContent} + {/* {template.endsWith(DEFAULT_CONTENT_PLACEHOLDER) && defaultContent} */}
); } @@ -119,10 +114,10 @@ export function CustomFields({ return ( - {previewNode || useDefaultContent ? ( + {previewNode ? ( <> - {previewNode || defaultContent} -
+ {previewNode} +
编辑 {contentNode}
@@ -143,20 +138,14 @@ export function CustomFields({ } function InputField({ value, disabled, onChange }: CustomFieldProps) { - return ( - onChange(e.target.value)} - disabled={disabled} - /> - ); + return onChange(e.target.value)} disabled={disabled} />; } function TextareaField({ value, disabled, onChange }: CustomFieldProps) { return ( onChange(e.target.value)} disabled={disabled} /> @@ -203,93 +192,6 @@ function FileField({ files }: CustomFieldProps) { ); } -function renderDefaultContent(field: CustomField, value: any, files?: FileFieldValue[]): ReactNode { - if (field.type === 'file') { - return {}} />; - } - if (value === undefined) { - return null; - } - if (isGameField(field)) { - const gameId = getGameId(value); - if (gameId) { - return ( -

- - {gameId} - -

- ); - } - } - if (field.type === 'dropdown' || field.type === 'radios') { - return

{field.options?.find((option) => option.value === value)?.label || value}

; - } - if (field.type === 'multi-select' && Array.isArray(value)) { - const labels = value.map( - (item) => field.options?.find((option) => option.value === item)?.label || item - ); - return

{labels.join(', ')}

; - } - return null; -} - -function isGameField(field: CustomField) { - return field.label.includes('游戏选择'); -} - -function getGameId(value: any): string | undefined { - if (typeof value === 'number') { - return formatGameId(value); - } - if (typeof value === 'string') { - try { - const parsedValue = JSON.parse(value); - if ( - parsedValue && - typeof parsedValue === 'object' && - (typeof parsedValue.id === 'string' || typeof parsedValue.id === 'number') - ) { - return formatGameId(parsedValue.id); - } - } catch (error) { - // ignore the error - } - return formatGameId(value); - } - if ( - value && - typeof value === 'object' && - (typeof value.id === 'string' || typeof value.id === 'number') - ) { - return formatGameId(value.id); - } -} - -function formatGameId(value: string | number): string | undefined { - const id = String(value); - return /^\d+$/.test(id) ? id : undefined; -} - -function getPreviewValue(field: CustomField, value: any) { - if (!isGameField(field)) { - return value; - } - return getGameId(value) ?? value; -} - -function formatFieldValue(value: any) { - if ( - value === undefined || - value === null || - typeof value === 'string' || - typeof value === 'number' - ) { - return value; - } - return JSON.stringify(value); -} - type PartialSome = Omit & { [key in K]?: T[K];