SpoolWeightUpdateModal.tsx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. import { useEffect, useState } from 'react';
  2. import { useTranslation } from 'react-i18next';
  3. import { Card, CardContent } from './Card';
  4. import { Button } from './Button';
  5. interface SpoolWeightUpdateModalProps {
  6. isOpen: boolean;
  7. filamentName: string;
  8. oldWeight: number | null;
  9. newWeight: number;
  10. onConfirm: (keepExisting: boolean) => void;
  11. onClose: () => void;
  12. }
  13. export function SpoolWeightUpdateModal({
  14. isOpen,
  15. filamentName,
  16. oldWeight,
  17. newWeight,
  18. onConfirm,
  19. onClose,
  20. }: SpoolWeightUpdateModalProps) {
  21. const { t } = useTranslation();
  22. const [keepExisting, setKeepExisting] = useState(false);
  23. useEffect(() => {
  24. if (isOpen) setKeepExisting(false);
  25. }, [isOpen]);
  26. if (!isOpen) return null;
  27. const oldWeightLabel = oldWeight !== null ? `${oldWeight}g` : '—';
  28. const newWeightLabel = `${newWeight}g`;
  29. return (
  30. <div
  31. className="fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4"
  32. onClick={onClose}
  33. >
  34. <Card className="w-full max-w-md" onClick={(e: React.MouseEvent) => e.stopPropagation()}>
  35. <CardContent className="p-6">
  36. <h3 className="text-lg font-semibold text-white mb-1">
  37. {t('settings.catalog.updateSpoolWeight')}
  38. </h3>
  39. <p className="text-bambu-gray text-sm mb-4">
  40. {filamentName}: {oldWeightLabel} → {newWeightLabel}
  41. </p>
  42. <div className="space-y-3">
  43. <label className="flex items-start gap-3 cursor-pointer p-3 rounded-lg border border-bambu-dark-tertiary hover:bg-bambu-dark transition-colors">
  44. <input
  45. type="radio"
  46. name="weight-update-mode"
  47. checked={!keepExisting}
  48. onChange={() => setKeepExisting(false)}
  49. className="mt-1 accent-bambu-green"
  50. />
  51. <div>
  52. <div className="text-sm font-medium text-white">
  53. {t('settings.catalog.applyToAllSpools')}
  54. </div>
  55. <div className="text-xs text-bambu-gray mt-0.5">
  56. {t('settings.catalog.applyToAllSpoolsDesc')}
  57. </div>
  58. </div>
  59. </label>
  60. <label className="flex items-start gap-3 cursor-pointer p-3 rounded-lg border border-bambu-dark-tertiary hover:bg-bambu-dark transition-colors">
  61. <input
  62. type="radio"
  63. name="weight-update-mode"
  64. checked={keepExisting}
  65. onChange={() => setKeepExisting(true)}
  66. className="mt-1 accent-bambu-green"
  67. />
  68. <div>
  69. <div className="text-sm font-medium text-white">
  70. {t('settings.catalog.keepExistingSpoolWeight')}
  71. </div>
  72. <div className="text-xs text-bambu-gray mt-0.5">
  73. {t('settings.catalog.keepExistingSpoolWeightDesc')}
  74. </div>
  75. </div>
  76. </label>
  77. </div>
  78. <div className="flex gap-3 mt-6">
  79. <Button variant="secondary" onClick={onClose} className="flex-1">
  80. {t('common.cancel')}
  81. </Button>
  82. <Button
  83. onClick={() => onConfirm(keepExisting)}
  84. className="flex-1 bg-bambu-green hover:bg-bambu-green-dark"
  85. >
  86. {t('common.confirm')}
  87. </Button>
  88. </div>
  89. </CardContent>
  90. </Card>
  91. </div>
  92. );
  93. }