SpamValidation.tsx 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import { AnimatePresence, motion } from 'framer-motion'
  2. import { CardContent, Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from 'ui'
  3. import { Admonition } from 'ui-patterns'
  4. import { Markdown } from '@/components/interfaces/Markdown'
  5. import { ValidateSpamResponse } from '@/data/auth/validate-spam-mutation'
  6. interface SpamValidationProps {
  7. spamRules?: ValidateSpamResponse['rules']
  8. }
  9. // [Joshen] According to API, we label as a spam risk as long as there are spam
  10. // rules identified with scores above 0. Scores are irrelevant in our context and
  11. // are hence not visualized in the UI
  12. export const SpamValidation = ({ spamRules = [] }: SpamValidationProps) => {
  13. const rules = spamRules.filter((rule) => rule.score >= 0)
  14. return (
  15. <AnimatePresence>
  16. {rules.length > 0 && (
  17. <motion.div
  18. className="border-b"
  19. initial={{ height: 0, opacity: 0 }}
  20. animate={{ height: 'auto', opacity: 1 }}
  21. exit={{ height: 0, opacity: 0 }}
  22. transition={{ duration: 0.2, ease: 'easeOut' }}
  23. >
  24. <CardContent className="py-6 flex flex-col gap-2">
  25. <Admonition
  26. type="destructive"
  27. title="Issues to resolve"
  28. description="This email is likely to be marked as spam by email servers. Please resolve the below issues before saving."
  29. className="bg-destructive-300/50 dark:bg-destructive-200 border-destructive-400"
  30. />
  31. <div className="flex flex-col gap-1">
  32. <div className="w-full border rounded-md overflow-hidden">
  33. <Table>
  34. <TableHeader>
  35. <TableRow>
  36. <TableHead>Warning</TableHead>
  37. <TableHead>Description</TableHead>
  38. </TableRow>
  39. </TableHeader>
  40. <TableBody>
  41. {rules.map((rule) => (
  42. <TableRow key={rule.name}>
  43. <TableCell className="font-mono">{rule.name}</TableCell>
  44. <TableCell>{rule.desc}</TableCell>
  45. </TableRow>
  46. ))}
  47. </TableBody>
  48. </Table>
  49. </div>
  50. <Markdown
  51. className="max-w-none! text-foreground-lighter text-xs mt-2"
  52. content="Spam validation is powered by [SpamAssassin](https://spamassassin.apache.org/doc.html). Full list of all available warnings can be found [here](https://gist.github.com/ychaouche/a2faff159c2a1fea16019156972c7f8b)."
  53. />
  54. </div>
  55. </CardContent>
  56. </motion.div>
  57. )}
  58. </AnimatePresence>
  59. )
  60. }