Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
J
Juno Frontend Vue
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Dhevan Muhammad
Juno Frontend Vue
Commits
e3d81eb9
Commit
e3d81eb9
authored
Mar 14, 2024
by
Dhevan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
crud use done
parent
058f162e
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
93 additions
and
9 deletions
+93
-9
FormPage.vue
src/components/Page/FormPage.vue
+48
-5
user.js
src/router/user.js
+2
-1
UserCreate.vue
src/views/user/UserCreate.vue
+3
-3
UserEdit.vue
src/views/user/UserEdit.vue
+40
-0
No files found.
src/components/Page/FormPage.vue
View file @
e3d81eb9
...
...
@@ -5,7 +5,17 @@
<h6>
{{
title
}}
</h6>
<hr
/>
</div>
<div
v-if=
"isFetching"
class=
"card-body p-5 text-center d-flex align-items-center justify-content-center"
style=
"min-height: 300px"
>
<div
class=
"spinner-border text-primary"
role=
"status"
>
<span
class=
"visually-hidden"
>
Loading...
</span>
</div>
</div>
<DynamicForm
v-if=
"!isFetching"
ref=
"createForm"
:schemas=
"schemas"
@
formSubmit=
"handleSubmit"
...
...
@@ -20,9 +30,14 @@
</template>
<
script
setup
>
import
{
ref
,
onBeforeMount
}
from
"vue"
;
import
{
useRouter
,
useRoute
}
from
"vue-router"
;
import
BasePage
from
"./BasePage.vue"
;
import
DynamicForm
from
"./../Form/DynamicForm.vue"
;
import
{
Swal
,
showLoading
,
hideLoading
}
from
"@/utils/alert.js"
;
const
emit
=
defineEmits
([
"saved"
,
"dataLoaded"
]);
const
route
=
useRoute
();
const
props
=
defineProps
({
schemas
:
{
type
:
Array
,
...
...
@@ -33,20 +48,29 @@ const props = defineProps({
default
:
""
,
},
api
:
{},
isEdit
:
{
default
:
false
,
},
});
const
createForm
=
ref
(
null
);
const
isFetching
=
ref
(
false
);
const
formValue
=
ref
({});
const
handleSubmit
=
async
(
payload
,
{
resetForm
})
=>
{
// console.log(payload)
// return
try
{
showLoading
();
const
response
=
await
props
.
api
.
store
(
payload
);
const
response
=
props
.
isEdit
?
await
props
.
api
.
update
(
route
.
params
.
id
,
payload
)
:
await
props
.
api
.
store
(
payload
);
hideLoading
();
Swal
.
fire
(
"Sukses"
,
""
,
"success"
);
if
(
!
props
.
isEdit
)
{
resetForm
();
emit
(
"created"
,
response
);
}
emit
(
"saved"
,
response
);
}
catch
(
err
)
{
console
.
log
(
err
);
if
(
err
.
response
&&
err
.
response
.
status
==
422
)
{
...
...
@@ -59,8 +83,6 @@ const handleSubmit = async (payload, { resetForm }) => {
}
};
const
formValue
=
ref
({});
onBeforeMount
(
async
()
=>
{
const
initialValue
=
{};
props
.
schemas
.
forEach
((
schema
)
=>
{
...
...
@@ -69,5 +91,26 @@ onBeforeMount(async () => {
}
});
formValue
.
value
=
initialValue
;
if
(
props
.
isEdit
)
{
isFetching
.
value
=
true
;
let
response
=
await
props
.
api
.
detail
(
route
.
params
.
id
);
const
data
=
response
.
result
;
emit
(
"dataLoaded"
,
data
);
props
.
schemas
.
forEach
((
schema
)
=>
{
if
(
schema
.
type
==
"password"
)
{
data
[
schema
.
name
]
=
null
;
}
if
(
schema
.
type
==
"checkbox"
)
{
if
(
data
[
schema
.
name
]
==
1
)
{
data
[
schema
.
name
]
=
true
;
}
else
{
data
[
schema
.
name
]
=
false
;
}
}
});
formValue
.
value
=
data
;
isFetching
.
value
=
false
;
}
});
</
script
>
src/router/user.js
View file @
e3d81eb9
import
UserProfile
from
"./../views/user/UserProfile.vue"
;
import
UserIndex
from
"./../views/user/UserIndex.vue"
;
import
UserCreate
from
"@/views/user/UserCreate.vue"
;
import
UserEdit
from
"@/views/user/UserEdit.vue"
;
export
const
userRoutes
=
[
{
path
:
"/user"
,
...
...
@@ -18,7 +19,7 @@ export const userRoutes = [
{
path
:
"/user/:id/edit"
,
name
:
"edit"
,
component
:
User
Index
,
component
:
User
Edit
,
},
{
path
:
"/user/profile"
,
...
...
src/views/user/UserCreate.vue
View file @
e3d81eb9
<
template
>
<form-page
title=
"Tambah User"
:schemas=
"schemas"
></form-page>
<form-page
title=
"Tambah User"
:schemas=
"schemas"
:api=
"UserApi"
></form-page>
</
template
>
<
script
setup
>
import
*
as
Yup
from
"yup"
;
import
FormPage
from
"@/components/Page/FormPage.vue"
;
import
{
UserApi
}
from
"@/api/user.js"
;
const
schemas
=
[
{
label
:
"Nama User"
,
...
...
@@ -29,7 +29,7 @@ const schemas = [
name
:
"password"
,
validation
:
Yup
.
string
().
required
().
label
(
"Password User"
),
cols
:
6
,
type
:
"password"
type
:
"password"
,
},
];
</
script
>
src/views/user/UserEdit.vue
0 → 100644
View file @
e3d81eb9
<
template
>
<form-page
:isEdit=
"true"
title=
"Edit User"
:schemas=
"schemas"
:api=
"UserApi"
></form-page>
</
template
>
<
script
setup
>
import
*
as
Yup
from
"yup"
;
import
FormPage
from
"@/components/Page/FormPage.vue"
;
import
{
UserApi
}
from
"@/api/user.js"
;
const
schemas
=
[
{
label
:
"Nama User"
,
name
:
"name"
,
validation
:
Yup
.
string
().
required
().
label
(
"Nama User"
),
cols
:
6
,
},
{
label
:
"Email"
,
name
:
"email"
,
validation
:
Yup
.
string
().
required
().
label
(
"Email User"
),
cols
:
6
,
},
{
label
:
"username"
,
name
:
"username"
,
validation
:
Yup
.
string
().
required
().
label
(
"Username"
),
cols
:
6
,
},
{
label
:
"Password User"
,
name
:
"password"
,
validation
:
Yup
.
string
().
required
().
label
(
"Password User"
),
cols
:
6
,
type
:
"password"
,
},
];
</
script
>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment