SkyeYoung commented on code in PR #3014: URL: https://github.com/apache/apisix-dashboard/pull/3014#discussion_r2075841582
########## src/components/form-slice/FormPartSSL/FormItemCertKeyList.tsx: ########## @@ -0,0 +1,107 @@ +import { Button, Fieldset, Stack, type FieldsetProps } from '@mantine/core'; +import { useTranslation } from 'react-i18next'; +import { useFieldArray, useFormContext } from 'react-hook-form'; +import { FormSection } from '../FormSection'; +import type { SSLPostType } from './schema'; +import type { PropsWithChildren } from 'react'; +import { FormItemTextareaWithUpload } from '@/components/form/TextareaWithUpload'; +import IconDelete from '~icons/material-symbols/delete-forever-outline'; + +const PairWrapper = ( + props: PropsWithChildren & Pick<FieldsetProps, 'legend'> +) => { + const { children, legend } = props; + return ( + <Fieldset p={8} mb={5} legend={legend}> + <Stack flex={1} gap={1}> + {children} + </Stack> + </Fieldset> + ); +}; + +const RequiredCertKey = () => { + const { t } = useTranslation(); + const { control } = useFormContext<SSLPostType>(); + return ( + <PairWrapper> + <FormItemTextareaWithUpload + control={control} + label={`${t('form.ssls.cert')} 1`} + name="cert" + required + /> + <FormItemTextareaWithUpload + control={control} + label={`${t('form.ssls.key')} 1`} + name="key" + required + /> + </PairWrapper> + ); +}; +const CertKeyPairList = () => { + const { t } = useTranslation(); + const certs = useFieldArray({ + name: 'certs', + }); + const keys = useFieldArray({ + name: 'keys', + }); + return ( + <> + {certs.fields.map((cert, idx) => ( + <PairWrapper + key={cert.id} + legend={ + <Button + leftSection={<IconDelete />} + justify="flex-end" + size="compact-xs" + color="red" + variant="outline" + onClick={() => { + certs.remove(idx); + keys.remove(idx); + }} + > + {t('form.ssls.cert_key_list.delete')} + </Button> + } + > + <FormItemTextareaWithUpload + key={cert.id} + name={`certs.${idx}`} + label={`${t('form.ssls.cert')} ${idx + 2}`} Review Comment: https://github.com/apache/apisix-dashboard/pull/3014#discussion_r2075813334 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@apisix.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org