mirror of
https://github.com/casdoor/casdoor.git
synced 2025-07-04 05:10:19 +08:00
feat: Reduce code duplication in form item rendering
This commit is contained in:
@ -50,6 +50,38 @@ const formItemLayout = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const renderFormItem = (signupItem) => {
|
||||||
|
const commonProps = {
|
||||||
|
name: signupItem.name.toLowerCase(),
|
||||||
|
label: signupItem.label || signupItem.name,
|
||||||
|
rules: [
|
||||||
|
{
|
||||||
|
required: signupItem.required,
|
||||||
|
message: i18next.t(`signup:Please input your ${signupItem.label || signupItem.name}!`),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!signupItem.type || signupItem.type === "Input") {
|
||||||
|
return (
|
||||||
|
<Form.Item {...commonProps}>
|
||||||
|
<Input placeholder={signupItem.placeholder} />
|
||||||
|
</Form.Item>
|
||||||
|
);
|
||||||
|
} else if (signupItem.type === "Single Choice" || signupItem.type === "Multiple Choices") {
|
||||||
|
return (
|
||||||
|
<Form.Item {...commonProps}>
|
||||||
|
<Select
|
||||||
|
mode={signupItem.type === "Multiple Choices" ? "multiple" : "single"}
|
||||||
|
placeholder={signupItem.placeholder}
|
||||||
|
showSearch={false}
|
||||||
|
options={signupItem.options.map(option => ({label: option, value: option}))}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
export const tailFormItemLayout = {
|
export const tailFormItemLayout = {
|
||||||
wrapperCol: {
|
wrapperCol: {
|
||||||
xs: {
|
xs: {
|
||||||
@ -694,217 +726,13 @@ class SignupPage extends React.Component {
|
|||||||
|
|
||||||
);
|
);
|
||||||
} else if (signupItem.name === "Gender") {
|
} else if (signupItem.name === "Gender") {
|
||||||
if (!signupItem.type) {
|
return renderFormItem(signupItem);
|
||||||
return (
|
|
||||||
<Form.Item
|
|
||||||
name={signupItem.name.toLowerCase()}
|
|
||||||
label={signupItem.label ? signupItem.label : signupItem.name}
|
|
||||||
rules={[
|
|
||||||
{
|
|
||||||
required: signupItem.required,
|
|
||||||
message: i18next.t(`signup:Please input your ${signupItem.label || signupItem.name}!`),
|
|
||||||
},
|
|
||||||
]}
|
|
||||||
>
|
|
||||||
<Input placeholder={signupItem.placeholder} />
|
|
||||||
</Form.Item>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (!signupItem.type || signupItem.type === "Input") {
|
|
||||||
return (
|
|
||||||
<Form.Item
|
|
||||||
name={signupItem.name.toLowerCase()}
|
|
||||||
label={signupItem.label ? signupItem.label : signupItem.name}
|
|
||||||
rules={[
|
|
||||||
{
|
|
||||||
required: signupItem.required,
|
|
||||||
message: i18next.t(`signup:Please input your ${signupItem.label}!`),
|
|
||||||
},
|
|
||||||
]}
|
|
||||||
>
|
|
||||||
<Input placeholder={signupItem.placeholder} />
|
|
||||||
</Form.Item>
|
|
||||||
);
|
|
||||||
} else if (signupItem.type === "Single Choice" || signupItem.type === "Multiple Choices") {
|
|
||||||
return (
|
|
||||||
<Form.Item
|
|
||||||
name={signupItem.name.toLowerCase()}
|
|
||||||
label={signupItem.label ? signupItem.label : signupItem.name}
|
|
||||||
rules={[
|
|
||||||
{
|
|
||||||
required: signupItem.required,
|
|
||||||
message: i18next.t(`Please select your ${signupItem.label || signupItem.name}!`),
|
|
||||||
},
|
|
||||||
]}
|
|
||||||
>
|
|
||||||
<Select
|
|
||||||
mode={signupItem.type === "Multiple Choices" ? "multiple" : "single"}
|
|
||||||
placeholder={signupItem.placeholder}
|
|
||||||
showSearch={false}
|
|
||||||
options={signupItem.options.map(option => ({label: option, value: option}))}
|
|
||||||
/>
|
|
||||||
</Form.Item>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} else if (signupItem.name === "Bio") {
|
} else if (signupItem.name === "Bio") {
|
||||||
if (!signupItem.type || signupItem === "") {
|
return renderFormItem(signupItem);
|
||||||
return (
|
|
||||||
<Form.Item
|
|
||||||
name={signupItem.name.toLowerCase()}
|
|
||||||
label={signupItem.label ? signupItem.label : signupItem.name}
|
|
||||||
rules={[
|
|
||||||
{
|
|
||||||
required: signupItem.required,
|
|
||||||
message: i18next.t(`signup:Please input your ${signupItem.label || signupItem.name}!`),
|
|
||||||
},
|
|
||||||
]}
|
|
||||||
>
|
|
||||||
<Input placeholder={signupItem.placeholder} />
|
|
||||||
</Form.Item>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (!signupItem.type || signupItem.type === "Input") {
|
|
||||||
return (
|
|
||||||
<Form.Item
|
|
||||||
name={signupItem.name.toLowerCase()}
|
|
||||||
label={signupItem.label ? signupItem.label : signupItem.name}
|
|
||||||
rules={[
|
|
||||||
{
|
|
||||||
required: signupItem.required,
|
|
||||||
message: i18next.t(`signup:Please input your ${signupItem.label}!`),
|
|
||||||
},
|
|
||||||
]}
|
|
||||||
>
|
|
||||||
<Input placeholder={signupItem.placeholder} />
|
|
||||||
</Form.Item>
|
|
||||||
);
|
|
||||||
} else if (signupItem.type === "Single Choice" || signupItem.type === "Multiple Choices") {
|
|
||||||
return (
|
|
||||||
<Form.Item
|
|
||||||
name={signupItem.name.toLowerCase()}
|
|
||||||
label={signupItem.label ? signupItem.label : signupItem.name}
|
|
||||||
rules={[
|
|
||||||
{
|
|
||||||
required: signupItem.required,
|
|
||||||
message: i18next.t(`Please select your ${signupItem.label || signupItem.name}!`),
|
|
||||||
},
|
|
||||||
]}
|
|
||||||
>
|
|
||||||
<Select
|
|
||||||
mode={signupItem.type === "Multiple Choices" ? "multiple" : "single"}
|
|
||||||
placeholder={signupItem.placeholder}
|
|
||||||
showSearch={false}
|
|
||||||
options={signupItem.options.map(option => ({label: option, value: option}))}
|
|
||||||
/>
|
|
||||||
</Form.Item>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} else if (signupItem.name === "Tag") {
|
} else if (signupItem.name === "Tag") {
|
||||||
if (!signupItem.type) {
|
return renderFormItem(signupItem);
|
||||||
return (
|
|
||||||
<Form.Item
|
|
||||||
name={signupItem.name.toLowerCase()}
|
|
||||||
label={signupItem.label ? signupItem.label : signupItem.name}
|
|
||||||
rules={[
|
|
||||||
{
|
|
||||||
required: signupItem.required,
|
|
||||||
message: i18next.t(`signup:Please input your ${signupItem.label || signupItem.name}!`),
|
|
||||||
},
|
|
||||||
]}
|
|
||||||
>
|
|
||||||
<Input placeholder={signupItem.placeholder} />
|
|
||||||
</Form.Item>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (!signupItem.type || signupItem.type === "Input") {
|
|
||||||
return (
|
|
||||||
<Form.Item
|
|
||||||
name={signupItem.name.toLowerCase()}
|
|
||||||
label={signupItem.label ? signupItem.label : signupItem.name}
|
|
||||||
rules={[
|
|
||||||
{
|
|
||||||
required: signupItem.required,
|
|
||||||
message: i18next.t(`signup:Please input your ${signupItem.label}!`),
|
|
||||||
},
|
|
||||||
]}
|
|
||||||
>
|
|
||||||
<Input placeholder={signupItem.placeholder} />
|
|
||||||
</Form.Item>
|
|
||||||
);
|
|
||||||
} else if (signupItem.type === "Single Choice" || signupItem.type === "Multiple Choices") {
|
|
||||||
return (
|
|
||||||
<Form.Item
|
|
||||||
name={signupItem.name.toLowerCase()}
|
|
||||||
label={signupItem.label ? signupItem.label : signupItem.name}
|
|
||||||
rules={[
|
|
||||||
{
|
|
||||||
required: signupItem.required,
|
|
||||||
message: i18next.t(`Please select your ${signupItem.label || signupItem.name}!`),
|
|
||||||
},
|
|
||||||
]}
|
|
||||||
>
|
|
||||||
<Select
|
|
||||||
mode={signupItem.type === "Multiple Choices" ? "multiple" : "single"}
|
|
||||||
placeholder={signupItem.placeholder}
|
|
||||||
showSearch={false}
|
|
||||||
options={signupItem.options.map(option => ({label: option, value: option}))}
|
|
||||||
/>
|
|
||||||
</Form.Item>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} else if (signupItem.name === "Education") {
|
} else if (signupItem.name === "Education") {
|
||||||
if (!signupItem.type) {
|
return renderFormItem(signupItem);
|
||||||
return (
|
|
||||||
<Form.Item
|
|
||||||
name={signupItem.name.toLowerCase()}
|
|
||||||
label={signupItem.label ? signupItem.label : signupItem.name}
|
|
||||||
rules={[
|
|
||||||
{
|
|
||||||
required: signupItem.required,
|
|
||||||
message: i18next.t(`signup:Please input your ${signupItem.label || signupItem.name}!`),
|
|
||||||
},
|
|
||||||
]}
|
|
||||||
>
|
|
||||||
<Input placeholder={signupItem.placeholder} />
|
|
||||||
</Form.Item>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (!signupItem.type || signupItem.type === "Input") {
|
|
||||||
return (
|
|
||||||
<Form.Item
|
|
||||||
name={signupItem.name.toLowerCase()}
|
|
||||||
label={signupItem.label ? signupItem.label : signupItem.name}
|
|
||||||
rules={[
|
|
||||||
{
|
|
||||||
required: signupItem.required,
|
|
||||||
message: i18next.t(`signup:Please input your ${signupItem.label}!`),
|
|
||||||
},
|
|
||||||
]}
|
|
||||||
>
|
|
||||||
<Input placeholder={signupItem.placeholder} />
|
|
||||||
</Form.Item>
|
|
||||||
);
|
|
||||||
} else if (signupItem.type === "Single Choice" || signupItem.type === "Multiple Choices") {
|
|
||||||
return (
|
|
||||||
<Form.Item
|
|
||||||
name={signupItem.name.toLowerCase()}
|
|
||||||
label={signupItem.label ? signupItem.label : signupItem.name}
|
|
||||||
rules={[
|
|
||||||
{
|
|
||||||
required: signupItem.required,
|
|
||||||
message: i18next.t(`Please select your ${signupItem.label || signupItem.name}!`),
|
|
||||||
},
|
|
||||||
]}
|
|
||||||
>
|
|
||||||
<Select
|
|
||||||
mode={signupItem.type === "Multiple Choices" ? "multiple" : "single"}
|
|
||||||
placeholder={signupItem.placeholder}
|
|
||||||
showSearch={false}
|
|
||||||
options={signupItem.options.map(option => ({label: option, value: option}))}
|
|
||||||
/>
|
|
||||||
</Form.Item>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user