refactor: Simplify validation logic and adjust campaign steps service parameters

This commit is contained in:
MehrdadAdabi 2025-11-26 18:45:57 +03:30
parent bbb6bfb7f7
commit 70959e878f
5 changed files with 11 additions and 23 deletions

View File

@ -6,6 +6,7 @@
"scripts": { "scripts": {
"dev": "vite", "dev": "vite",
"build": "tsc -b && vite build", "build": "tsc -b && vite build",
"buildOnly": "vite build",
"lint": "eslint .", "lint": "eslint .",
"preview": "vite preview" "preview": "vite preview"
}, },

View File

@ -75,10 +75,10 @@ const DynamicForm: FC<DynamicFormProps> = ({ fields, processId, stepId }) => {
field.Type === FieldTypes.پول) && field.Type === FieldTypes.پول) &&
typeof value === "number" typeof value === "number"
) { ) {
if (field && field.MinValue !== undefined && value < field?.MinValue) { if (field && field.MinValue !== undefined) {
return `مقدار باید بزرگتر یا مساوی ${field.MinValue} باشد.`; return `مقدار باید بزرگتر یا مساوی ${field.MinValue} باشد.`;
} }
if (field && field.MaxValue !== undefined && value > field?.MaxValue) { if (field && field.MaxValue !== undefined) {
return `مقدار باید کوچکتر یا مساوی ${field.MaxValue} باشد.`; return `مقدار باید کوچکتر یا مساوی ${field.MaxValue} باشد.`;
} }
} }

View File

@ -27,7 +27,7 @@ const StepFormPage: FC = () => {
useEffect(() => { useEffect(() => {
if (data && data.Fields) { if (data && data.Fields) {
const processedFields: LocalFieldDefinition[] = data.Fields.map((el) => { const processedFields: LocalFieldDefinition[] = data.Fields.map((el) => {
const field: LocalFieldDefinition = { const field: any = {
ID: el.ID, ID: el.ID,
Name: el.Name, Name: el.Name,
LatinName: el.LatinName, LatinName: el.LatinName,

View File

@ -10,10 +10,9 @@ const StepsPage: FC = () => {
const { campaignId } = useParams<{ campaignId: string }>(); const { campaignId } = useParams<{ campaignId: string }>();
const navigate = useNavigate(); const navigate = useNavigate();
const [steps, setSteps] = useState<GroupedCampaign[]>([]); const [steps, setSteps] = useState<GroupedCampaign[]>([]);
const [selectedStepId, setSelectedStepId] = useState<number | null>(null);
const { data, isLoading, error } = useQuery<Record<string, any>>({ const { data, isLoading, error } = useQuery<Record<string, any>>({
queryKey: ["dynamic-step"], queryKey: ["dynamic-step"],
queryFn: () => getCampaignStepsService(campaignId!), queryFn: () => getCampaignStepsService(),
}); });
useEffect(() => { useEffect(() => {
@ -165,11 +164,7 @@ const StepsPage: FC = () => {
focus-within:ring-2 focus-within:ring-blue-500 focus-within:ring-opacity-50 focus-within:ring-2 focus-within:ring-blue-500 focus-within:ring-opacity-50
transition-all duration-300 ease-in-out transform transition-all duration-300 ease-in-out transform
${
selectedStepId === step.stageID
? "bg-blue-50 border-blue-500 ring-2 ring-blue-500 ring-opacity-75 scale-105"
: "hover:scale-102"
}
`} `}
onClick={() => handleStepClick(step)} onClick={() => handleStepClick(step)}
tabIndex={0} // Make list item focusable tabIndex={0} // Make list item focusable
@ -180,11 +175,7 @@ const StepsPage: FC = () => {
w-10 h-10 sm:w-12 sm:h-12 rounded-full w-10 h-10 sm:w-12 sm:h-12 rounded-full
font-bold text-lg sm:text-xl font-bold text-lg sm:text-xl
mr-4 sm:mr-6 shrink-0 mr-4 sm:mr-6 shrink-0
${
selectedStepId === step.stageID
? "bg-blue-600 text-white"
: "bg-gray-200 text-gray-700"
}
transition-all duration-300 ease-in-out transition-all duration-300 ease-in-out
`} `}
> >
@ -194,11 +185,7 @@ const StepsPage: FC = () => {
<h2 <h2
className={` className={`
text-lg sm:text-xl font-semibold text-lg sm:text-xl font-semibold
${
selectedStepId === step.stageID
? "text-blue-800"
: "text-gray-800"
}
transition-colors duration-300 ease-in-out transition-colors duration-300 ease-in-out
`} `}
> >

View File

@ -324,9 +324,9 @@ export const createCircleService = async (
return res.data; return res.data;
}; };
export const getCampaignStepsService = async ( export const getCampaignStepsService = async (): Promise<
campaignId: string Record<string, any>
): Promise<Record<string, any>> => { > => {
const query = { const query = {
ProcessName: "run_process", ProcessName: "run_process",
OutputFields: ["*"], OutputFields: ["*"],