清理: - 删除 34 份过时文档(gap reports/QA临时报告/验收报告/阶段性文档) - 删除 docs/.hermes/skills 第三方 skills 副本(16 文件) - 删除 skills-lock.json 目录归集: - 根目录仅保留 README.md 索引 - product/ — 产品与架构设计(PRD + ARCHITECTURE + P2设计文档 + AI/企业路线图) - tracking/ — Chatwoot parity 开发跟踪 - requirements/ — M01-M12 模块需求 - plans/ — 历史实现计划 - parity/ — 路由 parity 与前端契约 - qa/ — QA 报告与测试计划 - ops/ — 运维部署 命名规范: - 全小写 kebab-case,禁止全大写文件名 - product/tracking/ops 用 NN- 序号前缀 - requirements 用 MNN- 两位零填充模块号 - plans/qa 用 YYYY-MM-DD- 日期前缀 - requirements M1-M9 零填充为 M01-M09(修复字典序) 同步更新: - backend/cmd/route_parity/main.go 路径默认值 - backend/scripts/parity_frontend_smoke.sh 报告路径 - 所有 docs 内部交叉引用 - .gitignore 排除编译产物 (backend/gochat, backend/route_parity) - 新增迁移 000052/000053 - 前端 WS 相关修改
103 lines
2.9 KiB
JavaScript
103 lines
2.9 KiB
JavaScript
import i18n from 'widget/i18n/index';
|
|
const defaultTranslations = Object.fromEntries(
|
|
Object.entries(i18n).filter(([key]) => key.includes('en'))
|
|
).en;
|
|
|
|
export const standardFieldKeys = {
|
|
emailAddress: {
|
|
key: 'EMAIL_ADDRESS',
|
|
label: 'Email Id',
|
|
placeholder: 'Please enter your email address',
|
|
},
|
|
fullName: {
|
|
key: 'FULL_NAME',
|
|
label: 'Full Name',
|
|
placeholder: 'Please enter your full name',
|
|
},
|
|
phoneNumber: {
|
|
key: 'PHONE_NUMBER',
|
|
label: 'Phone Number',
|
|
placeholder: 'Please enter your phone number',
|
|
},
|
|
};
|
|
|
|
export const getLabel = ({ key, label }) => {
|
|
return defaultTranslations.PRE_CHAT_FORM.FIELDS[key]
|
|
? defaultTranslations.PRE_CHAT_FORM.FIELDS[key].LABEL
|
|
: label;
|
|
};
|
|
export const getPlaceHolder = ({ key, placeholder }) => {
|
|
return defaultTranslations.PRE_CHAT_FORM.FIELDS[key]
|
|
? defaultTranslations.PRE_CHAT_FORM.FIELDS[key].PLACEHOLDER
|
|
: placeholder;
|
|
};
|
|
|
|
export const getCustomFields = ({ standardFields, customAttributes }) => {
|
|
let customFields = [];
|
|
const { pre_chat_fields: preChatFields } = standardFields;
|
|
customAttributes.forEach(attribute => {
|
|
const itemExist = preChatFields.find(
|
|
item => item.name === attribute.attribute_key
|
|
);
|
|
if (!itemExist) {
|
|
customFields.push({
|
|
label: attribute.attribute_display_name,
|
|
placeholder: attribute.attribute_display_name,
|
|
name: attribute.attribute_key,
|
|
type: attribute.attribute_display_type,
|
|
values: attribute.attribute_values,
|
|
field_type: attribute.attribute_model,
|
|
regex_pattern: attribute.regex_pattern,
|
|
regex_cue: attribute.regex_cue,
|
|
required: false,
|
|
enabled: false,
|
|
});
|
|
}
|
|
});
|
|
return customFields;
|
|
};
|
|
|
|
export const getFormattedPreChatFields = ({ preChatFields }) => {
|
|
if (!preChatFields) return [];
|
|
return preChatFields.map(item => {
|
|
return {
|
|
...item,
|
|
label: getLabel({
|
|
key: item.name,
|
|
label: item.label ? item.label : item.name,
|
|
}),
|
|
placeholder: getPlaceHolder({
|
|
key: item.name,
|
|
placeholder: item.placeholder ? item.placeholder : item.name,
|
|
}),
|
|
};
|
|
});
|
|
};
|
|
|
|
export const getPreChatFields = ({
|
|
preChatFormOptions = {},
|
|
customAttributes = [],
|
|
}) => {
|
|
// preChatFormOptions can be null when the inbox has no pre-chat form configured.
|
|
// Default parameters only apply for undefined, not null.
|
|
const options = preChatFormOptions || {};
|
|
const { pre_chat_message, pre_chat_fields } = options;
|
|
let customFields = {};
|
|
let preChatFields = {};
|
|
|
|
const formattedPreChatFields = getFormattedPreChatFields({
|
|
preChatFields: pre_chat_fields,
|
|
});
|
|
|
|
customFields = getCustomFields({
|
|
standardFields: { pre_chat_fields: formattedPreChatFields },
|
|
customAttributes,
|
|
});
|
|
preChatFields = [...formattedPreChatFields, ...customFields];
|
|
|
|
return {
|
|
pre_chat_message,
|
|
pre_chat_fields: preChatFields,
|
|
};
|
|
};
|