1
0

crm.rs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*
  2. Tiny CRM: A port of the Yew CRM example to Dioxus.
  3. */
  4. use dioxus::prelude::*;
  5. use dioxus_router::{Link, Route, Router};
  6. fn main() {
  7. dioxus_desktop::launch(app);
  8. }
  9. #[derive(Clone, Debug, Default)]
  10. pub struct Client {
  11. pub first_name: String,
  12. pub last_name: String,
  13. pub description: String,
  14. }
  15. fn app(cx: Scope) -> Element {
  16. let clients = use_ref(cx, || vec![] as Vec<Client>);
  17. let firstname = use_state(cx, String::new);
  18. let lastname = use_state(cx, String::new);
  19. let description = use_state(cx, String::new);
  20. cx.render(rsx!(
  21. body {
  22. margin_left: "35%",
  23. link {
  24. rel: "stylesheet",
  25. href: "https://unpkg.com/purecss@2.0.6/build/pure-min.css",
  26. integrity: "sha384-Uu6IeWbM+gzNVXJcM9XV3SohHtmWE+3VGi496jvgX1jyvDTXfdK+rfZc8C1Aehk5",
  27. crossorigin: "anonymous",
  28. }
  29. h1 { "Dioxus CRM Example" }
  30. Router {
  31. Route { to: "/",
  32. div { class: "crm",
  33. h2 { margin_bottom: "10px", "List of clients" }
  34. div { class: "clients", margin_left: "10px",
  35. clients.read().iter().map(|client| rsx!(
  36. div { class: "client", style: "margin-bottom: 50px",
  37. p { "First Name: {client.first_name}" }
  38. p { "Last Name: {client.last_name}" }
  39. p { "Description: {client.description}" }
  40. })
  41. )
  42. }
  43. Link { to: "/new", class: "pure-button pure-button-primary", "Add New" }
  44. Link { to: "/settings", class: "pure-button", "Settings" }
  45. }
  46. }
  47. Route { to: "/new",
  48. div { class: "crm",
  49. h2 { margin_bottom: "10px", "Add new client" }
  50. form { class: "pure-form",
  51. input {
  52. class: "new-client firstname",
  53. placeholder: "First name",
  54. value: "{firstname}",
  55. oninput: move |e| firstname.set(e.value.clone())
  56. }
  57. input {
  58. class: "new-client lastname",
  59. placeholder: "Last name",
  60. value: "{lastname}",
  61. oninput: move |e| lastname.set(e.value.clone())
  62. }
  63. textarea {
  64. class: "new-client description",
  65. placeholder: "Description",
  66. value: "{description}",
  67. oninput: move |e| description.set(e.value.clone())
  68. }
  69. }
  70. button {
  71. class: "pure-button pure-button-primary",
  72. onclick: move |_| {
  73. clients.write().push(Client {
  74. description: description.to_string(),
  75. first_name: firstname.to_string(),
  76. last_name: lastname.to_string(),
  77. });
  78. description.set(String::new());
  79. firstname.set(String::new());
  80. lastname.set(String::new());
  81. },
  82. "Add New"
  83. }
  84. Link { to: "/", class: "pure-button", "Go Back" }
  85. }
  86. }
  87. Route { to: "/settings",
  88. div {
  89. h2 { margin_bottom: "10px", "Settings" }
  90. button {
  91. background: "rgb(202, 60, 60)",
  92. class: "pure-button pure-button-primary",
  93. onclick: move |_| clients.write().clear(),
  94. "Remove all clients"
  95. }
  96. Link { to: "/", class: "pure-button pure-button-primary", "Go Back" }
  97. }
  98. }
  99. }
  100. }
  101. ))
  102. }