fix(ct): статус СТ до оповещения и без ложной плашки Teams

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Тимур Городецкий
2026-09-03 14:26:38 +05:00
parent 899b14b869
commit cc44f77975
2 changed files with 15 additions and 11 deletions
@@ -67,7 +67,6 @@ export const Step4Approval: React.FC<Props> = (props) => {
)}
{a.ct?.status === "on_approval" && <Alert variant="info">СТ находится на согласовании.</Alert>}
{a.notifyWarning && <Alert variant="warn">{a.notifyWarning}</Alert>}
{/* Approval chain */}
<section className={styles.section}>
@@ -49,7 +49,6 @@ export function useStep4Approval(args: UseStep4ApprovalArgs) {
const [actionDialog, setActionDialog] = useState<ActionDialogState | null>(null);
const [isSubmitting, setIsSubmitting] = useState(false);
const [submitError, setSubmitError] = useState<string | null>(null);
const [notifyWarning, setNotifyWarning] = useState<string | null>(null);
const [isSendingToIncore, setIsSendingToIncore] = useState(false);
const [incoreStep, setIncoreStep] = useState<IncoreStep | null>(null);
const [incoreError, setIncoreError] = useState<string | null>(null);
@@ -236,8 +235,9 @@ export function useStep4Approval(args: UseStep4ApprovalArgs) {
try {
await service.triggerApprovalNotification(spId);
} catch (e) {
// Оповещение — best-effort: поток может ответить с таймаутом (504), хотя сообщение
// уже ушло. Не пугаем пользователя ложной плашкой, только логируем для отладки.
console.error('[Step4] triggerApprovalNotification failed for spId', spId, e);
setNotifyWarning('Голос записан, но уведомление в Teams не удалось отправить. Проверьте Power Automate.');
}
};
@@ -250,6 +250,18 @@ export function useStep4Approval(args: UseStep4ApprovalArgs) {
setChain(updatedChain);
onSave({ approvalChain: updatedChain });
const allApproved = updatedChain.every(
(m) => m.status === 'approved' || m.status === 'skipped' || m.status === 'recommends',
);
// Финальное согласование: сначала переводим СТ в «Согласовано», и только ПОТОМ
// шлём оповещение. Иначе поток прочитает статус ещё «На согласовании» и отправит
// не то письмо. Порядок как в ветке отклонения (сначала статус, затем notify).
if (allApproved) {
await service.updateCTStatus(ct!.id, 'approved');
onSave({ ct: { ...ct!, status: 'approved' } });
}
if (currentMember?.spApprovalId) {
await notify(currentMember.spApprovalId);
}
@@ -259,12 +271,7 @@ export function useStep4Approval(args: UseStep4ApprovalArgs) {
await notify(nextPending.spApprovalId);
}
const allApproved = updatedChain.every(
(m) => m.status === 'approved' || m.status === 'skipped' || m.status === 'recommends',
);
if (allApproved) {
await service.updateCTStatus(ct!.id, 'approved');
onSave({ ct: { ...ct!, status: 'approved' } });
onStepComplete(4);
}
} else {
@@ -321,8 +328,8 @@ export function useStep4Approval(args: UseStep4ApprovalArgs) {
try {
await service.triggerApprovalNotification(firstApprover.spApprovalId);
} catch (e) {
// best-effort (см. notify выше) — ложную плашку не показываем.
console.error('[Step4] triggerApprovalNotification (send) failed for spId', firstApprover.spApprovalId, e);
setNotifyWarning('СТ отправлена на согласование, но уведомление в Teams не удалось отправить. Проверьте Power Automate.');
}
}
@@ -432,8 +439,6 @@ export function useStep4Approval(args: UseStep4ApprovalArgs) {
ct,
chain,
submitError,
notifyWarning,
dismissNotifyWarning: () => setNotifyWarning(null),
isSubmitting,
isSendingToIncore,
incoreStep,