Skip to content
GitLab
Explore
Projects
Groups
Topics
Snippets
Projects
Groups
Topics
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Register
Sign in
Toggle navigation
Menu
UPSMF
uphrh-smf-web
Commits
132ea968
Unverified
Commit
132ea968
authored
2 years ago
by
devendra-tarento
Committed by
GitHub
2 years ago
Browse files
Options
Download
Plain Diff
Merge pull request #12 from UPHRH-platform/delete-form
Delete form
parents
2aa78683
f12a1754
master
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/components/form/AddForm.js
+58
-18
src/components/form/AddForm.js
src/components/form/ListForms.js
+59
-18
src/components/form/ListForms.js
src/constants/LangConstants.ts
+2
-1
src/constants/LangConstants.ts
src/helpers/auth.js
+9
-0
src/helpers/auth.js
with
128 additions
and
37 deletions
+128
-37
src/components/form/AddForm.js
+
58
−
18
View file @
132ea968
...
...
@@ -16,6 +16,7 @@ import Header from "./../common/Header";
import
Sortable
from
"
sortablejs
"
;
import
{
BtnTwo
}
from
"
../buttons/BtnTwo
"
;
import
{
BtnOne
}
from
"
../buttons/BtnOne
"
;
import
{
ConfirmModal
}
from
"
../../components/modal
"
;
let
strings
=
new
LocalizedStrings
(
translations
);
...
...
@@ -27,6 +28,7 @@ class AddForm extends Component {
this
.
resetElements
=
this
.
resetElements
.
bind
(
this
);
this
.
handleChange
=
this
.
handleChange
.
bind
(
this
);
this
.
submit
=
this
.
submit
.
bind
(
this
);
this
.
saveFormDetails
=
this
.
saveFormDetails
.
bind
(
this
);
this
.
state
=
{
language
:
"
en
"
,
formElements
:
[],
...
...
@@ -39,6 +41,7 @@ class AddForm extends Component {
fields
:
[],
},
breadcrumbData
:
[],
showDuplicateConfirmModal
:
false
,
};
}
...
...
@@ -276,30 +279,46 @@ class AddForm extends Component {
}
if
(
allowSubmission
)
{
FormService
.
add
(
formData
).
then
(
(
response
)
=>
{
if
(
response
.
statusInfo
.
statusCode
===
APP
.
CODE
.
SUCCESS
)
{
Notify
.
success
(
response
.
statusInfo
.
statusMessage
);
// this.props.updateParent(response.responseData.id);
setTimeout
(()
=>
{
this
.
props
.
history
.
push
(
"
/manage?tab=1
"
);
},
500
);
}
else
{
Notify
.
error
(
response
.
statusInfo
.
errorMessage
);
}
},
(
error
)
=>
{
error
.
statusInfo
?
Notify
.
error
(
error
.
statusInfo
.
errorMessage
)
:
Notify
.
error
(
error
.
message
);
}
);
this
.
saveFormDetails
(
formData
,
false
);
}
else
{
Notify
.
error
(
"
Kindly fill all the fields
"
);
}
};
saveFormDetails
=
(
formData
,
isDuplicate
)
=>
{
FormService
.
add
(
formData
).
then
(
(
response
)
=>
{
if
(
response
.
statusInfo
.
statusCode
===
APP
.
CODE
.
SUCCESS
)
{
if
(
isDuplicate
)
{
Notify
.
success
(
"
Duplicate form is added successfully
"
);
this
.
setState
({
showDuplicateConfirmModal
:
false
});
}
else
{
Notify
.
success
(
response
.
statusInfo
.
statusMessage
);
}
// this.props.updateParent(response.responseData.id);
setTimeout
(()
=>
{
this
.
props
.
history
.
push
(
"
/manage?tab=1
"
);
},
500
);
}
else
{
Notify
.
error
(
response
.
statusInfo
.
errorMessage
);
}
},
(
error
)
=>
{
error
.
statusInfo
?
Notify
.
error
(
error
.
statusInfo
.
errorMessage
)
:
Notify
.
error
(
error
.
message
);
}
);
}
duplicateForm
=
()
=>
{
let
formData
=
{...
this
.
state
.
formDetails
,
id
:
""
,
title
:
'
Copy of
'
+
this
.
state
.
formDetails
.
title
};
this
.
saveFormDetails
(
formData
,
true
);
}
render
()
{
const
{
formDetails
,
showDuplicateConfirmModal
}
=
this
.
state
;
strings
.
setLanguage
(
localStorage
.
getItem
(
"
language
"
)
||
this
.
state
.
language
);
...
...
@@ -339,6 +358,18 @@ class AddForm extends Component {
/
>
<
/div
>
)}
{
this
.
state
.
formDetails
.
status
===
LANG
.
FORM_STATUS
.
DRAFT
&&
(
<
div
className
=
"
mr-3
"
>
<
BtnOne
label
=
"
Duplicate
"
btnType
=
"
button
"
isLink
=
{
false
}
link
=
""
clickHandler
=
{(
e
)
=>
this
.
setState
({
showDuplicateConfirmModal
:
true
})}
/
>
<
/div
>
)}
<
div
className
=
"
mr-0
"
>
<
BtnTwo
label
=
"
Submit
"
...
...
@@ -514,6 +545,15 @@ class AddForm extends Component {
<
/div
>
<
/div
>
<
/div
>
{
showDuplicateConfirmModal
&&
(
<
ConfirmModal
title
=
"
Duplicate Form
"
onConfirm
=
{
this
.
duplicateForm
}
onCancel
=
{()
=>
{
this
.
setState
({
showDuplicateConfirmModal
:
false
});
}}
>
Do
you
want
to
delete
{
formDetails
?.
title
}
?
<
/ConfirmModal
>
)}
<
/Fragment
>
);
}
...
...
This diff is collapsed.
Click to expand it.
src/components/form/ListForms.js
+
59
−
18
View file @
132ea968
...
...
@@ -4,12 +4,17 @@ import { FormService } from "../../services/form.service";
import
{
APP
,
LANG
}
from
"
../../constants
"
;
import
Notify
from
"
../../helpers/notify
"
;
import
{
BtnTwo
}
from
"
../buttons
"
;
import
{
ConfirmModal
}
from
"
../../components/modal
"
;
import
Helper
from
"
../../helpers/auth
"
;
class
ListForms
extends
Component
{
constructor
(
props
)
{
super
(
props
);
this
.
state
=
{
forms
:
[],
isAdmin
:
Helper
.
isAdmin
(),
formToDelete
:
{},
showConfirmModal
:
false
,
};
this
.
getFormShortCode
=
this
.
getFormShortCode
.
bind
(
this
);
}
...
...
@@ -62,24 +67,7 @@ class ListForms extends Component {
}
else
{
formData
.
status
=
LANG
.
FORM_STATUS
.
UNPUBLISH
;
}
FormService
.
add
(
formData
).
then
(
(
response
)
=>
{
if
(
response
.
statusInfo
.
statusCode
===
APP
.
CODE
.
SUCCESS
)
{
Notify
.
success
(
response
.
statusInfo
.
statusMessage
);
// this.props.updateParent(response.responseData.id);
setTimeout
(()
=>
{
this
.
getAllForms
();
},
500
);
}
else
{
Notify
.
error
(
response
.
statusInfo
.
errorMessage
);
}
},
(
error
)
=>
{
error
.
statusInfo
?
Notify
.
error
(
error
.
statusInfo
.
errorMessage
)
:
Notify
.
error
(
error
.
message
);
}
);
this
.
saveFormDetails
(
formData
,
false
);
};
searchForms
=
(
event
)
=>
{
...
...
@@ -105,7 +93,40 @@ class ListForms extends Component {
// history: PropTypes.object.isRequired,
// };
deleteForm
=
()
=>
{
const
formData
=
{...
this
.
state
.
formToDelete
,
status
:
LANG
.
FORM_STATUS
.
DELETED
}
this
.
saveFormDetails
(
formData
,
true
);
}
saveFormDetails
=
(
formData
,
isDelete
)
=>
{
FormService
.
add
(
formData
).
then
(
(
response
)
=>
{
if
(
response
.
statusInfo
.
statusCode
===
APP
.
CODE
.
SUCCESS
)
{
if
(
isDelete
)
{
this
.
setState
({
showConfirmModal
:
false
});
Notify
.
success
(
"
Form deleted successfully
"
)
}
else
{
Notify
.
success
(
response
.
statusInfo
.
statusMessage
);
}
// this.props.updateParent(response.responseData.id);
setTimeout
(()
=>
{
this
.
getAllForms
();
},
500
);
}
else
{
Notify
.
error
(
response
.
statusInfo
.
errorMessage
);
}
},
(
error
)
=>
{
error
.
statusInfo
?
Notify
.
error
(
error
.
statusInfo
.
errorMessage
)
:
Notify
.
error
(
error
.
message
);
}
);
}
render
()
{
const
{
isAdmin
,
showConfirmModal
,
formToDelete
}
=
this
.
state
;
return
(
<
Fragment
>
<
div
className
=
"
row pt-2
"
>
...
...
@@ -194,7 +215,18 @@ class ListForms extends Component {
<
/td
>
<
td
className
=
"
td-preview
"
>
{
form
.
status
===
LANG
.
FORM_STATUS
.
DRAFT
&&
(
<>
<
Link
to
=
{
`/forms/
${
form
.
id
}
/edit`
}
>
Edit
<
/Link
>
{
isAdmin
&&
(
<
span
className
=
"
ml-3 text-danger pointer
"
onClick
=
{
()
=>
{
this
.
setState
({
formToDelete
:
form
,
showConfirmModal
:
true
})
}
}
>
Delete
<
/span
>
)}
<
/
>
)}
{
form
.
status
!==
LANG
.
FORM_STATUS
.
DRAFT
&&
(
<
span
className
=
"
font-weight-bold black-16
"
>
Edit
<
/span
>
...
...
@@ -206,6 +238,15 @@ class ListForms extends Component {
<
/table
>
<
/div
>
<
/div
>
{
showConfirmModal
&&
(
<
ConfirmModal
title
=
"
Delete Form
"
onConfirm
=
{
this
.
deleteForm
}
onCancel
=
{()
=>
{
this
.
setState
({
showConfirmModal
:
false
,
formToDelete
:
{}});
}}
>
Do
you
want
to
delete
{
formToDelete
?.
title
}
?
<
/ConfirmModal
>
)}
<
/Fragment
>
);
}
...
...
This diff is collapsed.
Click to expand it.
src/constants/LangConstants.ts
+
2
−
1
View file @
132ea968
...
...
@@ -28,7 +28,8 @@ export const LANG = {
APPROVED
:
"
APPROVED
"
,
REJECTED
:
"
REJECTED
"
,
LEAD_INSPECTION_COMPLETED
:
"
LEADINSCOMPLETED
"
,
ASSISTING_INSPECTION_COMPLETED
:
"
INSCOMPLETED
"
ASSISTING_INSPECTION_COMPLETED
:
"
INSCOMPLETED
"
,
DELETED
:
"
DELETED
"
},
COL
:
{
1
:
1
,
...
...
This diff is collapsed.
Click to expand it.
src/helpers/auth.js
+
9
−
0
View file @
132ea968
...
...
@@ -31,6 +31,15 @@ const Auth = {
}
else
{
return
false
;
}
},
isAdmin
()
{
const
userRole
=
this
.
getUserRole
();
if
(
userRole
===
APP
.
ROLE
.
SUPER_ADMIN
||
userRole
===
APP
.
ROLE
.
REGULATOR
)
{
return
true
;
}
else
{
return
false
;
}
}
};
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Topics
Snippets