Advertisement
Guest User

Untitled

a guest
Apr 21st, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.61 KB | None | 0 0
  1. const CourseCard = ({
  2. classes,
  3. id,
  4. status,
  5. image,
  6. name,
  7. summary,
  8. progress,
  9. price
  10. }) => {
  11. // Nova variável para armazenar só o comportamento
  12. const actions = [];
  13.  
  14. // removido a variável renderActions
  15. let posExtraClass, posLabel;
  16.  
  17. if (status === "ACTIVE") {
  18. if (progress && progress.length > 0) {
  19. const progressTotal = progress.length;
  20. const progressCount = progress.filter(p => p.status === "DONE").length;
  21.  
  22. if (progressCount === progressTotal) {
  23. posLabel = "Concluído";
  24. } else if (progressCount === 0) {
  25. posLabel = "Não iniciado";
  26. } else {
  27. const progressPercent = Math.floor(
  28. (progressCount * 100) / progressTotal
  29. );
  30. posLabel = `Progresso: ${progressPercent}%`;
  31. }
  32.  
  33. // alterado de renderActions para actions
  34. actions.push({
  35. label: progressCount === 0 ? "Começar" : "Continuar"
  36. });
  37. } else {
  38. posLabel = price ? `Preço: R$ ${price}` : "Grátis";
  39. posExtraClass = classes.posHighlight;
  40.  
  41. // alterado de renderActions para actions
  42. actions.push({ label: "Saber mais" });
  43. actions.push(
  44. price
  45. ? { label: "Comprar", link: `/payment/course/${id}` }
  46. : { label: "Começar" }
  47. );
  48. }
  49. } else {
  50. posLabel = "Em breve...";
  51.  
  52. // alterado de renderActions para actions
  53. actions.push({ label: "Saber mais" });
  54. }
  55.  
  56. return (
  57. <Card className={classes.card}>
  58. <CardActionArea disabled={status !== "ACTIVE"}>
  59. <CardMedia
  60. className={classNames(classes.media, {
  61. [classes.mediaDisabled]: status !== "ACTIVE"
  62. })}
  63. image={`/images/${image}`}
  64. title={name}
  65. />
  66. <CardContent>
  67. <Typography gutterBottom variant="h5" component="h2">
  68. {name}
  69. </Typography>
  70. {posLabel && (
  71. <Typography
  72. className={classNames(classes.pos, posExtraClass)}
  73. color="textSecondary"
  74. >
  75. {posLabel}
  76. </Typography>
  77. )}
  78. <Typography component="p">{summary}</Typography>
  79. </CardContent>
  80. </CardActionArea>
  81.  
  82. {/* Mapeia cada ação para a camada de apresentação */}
  83. <CardActions>
  84. {actions.map(action => (
  85. <Button
  86. key={action.label}
  87. size="small"
  88. color="primary"
  89. component={action.link ? Link : "button"}
  90. to={action.link}
  91. >
  92. {action.label}
  93. </Button>
  94. ))}
  95. </CardActions>
  96. </Card>
  97. );
  98. };
  99.  
  100. export default withStyles(styles)(CourseCard);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement