Team SendouForm finalized, custom roles (#3156)
Some checks are pending
E2E Tests / e2e (push) Waiting to run
Tests and checks on push / run-checks-and-tests (push) Waiting to run
Updates translation progress / update-translation-progress-issue (push) Waiting to run

This commit is contained in:
Kalle
2026-06-14 09:53:18 +03:00
committed by GitHub
parent 0f1b9b962c
commit 4c50ef0e7e
66 changed files with 894 additions and 343 deletions

View File

@@ -16,6 +16,8 @@ type ArrayFormFieldProps = Omit<FormFieldProps<"array">, "field"> & {
isObjectArray?: boolean;
sortable?: boolean;
itemInitialValue?: unknown;
addable?: boolean;
canRemoveItem?: (itemValue: unknown, index: number) => boolean;
};
export function ArrayFormField({
@@ -31,6 +33,8 @@ export function ArrayFormField({
isObjectArray,
sortable,
itemInitialValue,
addable = true,
canRemoveItem,
}: ArrayFormFieldProps) {
const { t } = useTranslation(["common"]);
const { translatedLabel, translatedBottomText, translatedError } =
@@ -89,7 +93,9 @@ export function ArrayFormField({
// so it shouldn't offer a remove button (you can't go below one visible row
// anyway). A lone edited row stays removable so the only item can be cleared.
const canRemoveAt = (index: number) =>
count > min && (count > minVisible || !isPristineItem(value[index]));
(canRemoveItem ? canRemoveItem(value[index], index) : true) &&
count > min &&
(count > minVisible || !isPristineItem(value[index]));
const handleRemoveAt = (index: number) => {
const next = value.filter((_, i) => i !== index);
@@ -147,16 +153,18 @@ export function ArrayFormField({
{translatedBottomText && !translatedError ? (
<FormMessage type="info">{translatedBottomText}</FormMessage>
) : null}
<SendouButton
size="small"
variant="outlined"
icon={<Plus />}
onPress={handleAdd}
isDisabled={count >= max}
className="m-0-auto"
>
{t("common:actions.add")}
</SendouButton>
{addable ? (
<SendouButton
size="small"
variant="outlined"
icon={<Plus />}
onPress={handleAdd}
isDisabled={count >= max}
className="m-0-auto"
>
{t("common:actions.add")}
</SendouButton>
) : null}
</div>
);
}