UpdateAccountView.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <script>
  2. import { defineComponent } from 'vue'
  3. import Sidebar from '@/components/Sidebar.vue'
  4. import Cookies from 'js-cookie'
  5. import { useRouter } from 'vue-router'
  6. import axios from 'axios'
  7. import { config } from '@/main.js'
  8. export default defineComponent({
  9. name: 'UpdateAccountView',
  10. setup() {
  11. const router = useRouter()
  12. // no this here
  13. if (!Cookies.get('token') || !Cookies.get('token').startsWith('HajeebToken'))
  14. return router.push('/profile/myself')
  15. return { router }
  16. },
  17. components: { Sidebar },
  18. methods: {
  19. async handleSubmit(e) {
  20. e.preventDefault()
  21. if (!this.signedIn()) return this.router.push('/login');
  22. document.getElementById('submit').disabled = true
  23. const formData = new FormData(e.target);
  24. const response = await axios.post(`${config.serverURL}/video/upload`, formData, {
  25. withCredentials: true,
  26. })
  27. if(response.data.error) {
  28. alert(`Upload error: ${response.data.message}`);
  29. return console.error(response.data);
  30. }
  31. if(response.data.id) {
  32. alert(`Video uploaded successfully!`);
  33. return this.router.push(`/profile/myself`);
  34. }
  35. },
  36. signedIn() {
  37. return Cookies.get('token') && Cookies.get('token').startsWith('HajeebToken')
  38. },
  39. },
  40. })
  41. </script>
  42. <template>
  43. <div class="main">
  44. <Sidebar />
  45. <div class="update-container">
  46. <form class="update" id="form" @submit="handleSubmit" enctype="multipart/form-data">
  47. <img src="/assets/hajeebtok.png" width="300px" alt="HajeebTok logo" />
  48. <input
  49. type="file"
  50. name="picture"
  51. accept="image/png, image/jpeg, image/jpg, image/webp"
  52. />
  53. <input type="text" placeholder="title" name="title" />
  54. <input type="text" placeholder="description" name="description" />
  55. <input type="submit" value="update Account" id="submit" />
  56. </form>
  57. </div>
  58. </div>
  59. </template>
  60. <style scoped>
  61. .update-container {
  62. width: 100vw;
  63. height: 100vh;
  64. margin: 0;
  65. position: absolute;
  66. display: flex;
  67. justify-content: center;
  68. align-items: center;
  69. top: 0;
  70. }
  71. .update {
  72. background-color: var(--secondary-background-color);
  73. color: white;
  74. padding: 10px;
  75. border-radius: 5px;
  76. display: flex;
  77. flex-direction: column;
  78. align-items: center;
  79. justify-self: center;
  80. gap: 10px;
  81. }
  82. input {
  83. font-family: 'Knewave', system-ui;
  84. font-size: 30px;
  85. border: 2px solid var(--accent-color);
  86. border-radius: 5px;
  87. }
  88. input:focus {
  89. outline: none;
  90. }
  91. </style>