Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
concept-front-mojsprat-v2
Project
Project
Details
Activity
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
Djordje Mutavdzic
concept-front-mojsprat-v2
Commits
4a8a1a6c
Commit
4a8a1a6c
authored
Jun 30, 2022
by
Djordje
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add action handlers
parent
f9fc9f48
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
195 additions
and
1 deletion
+195
-1
package.json
package.json
+2
-1
data-manager.js
src/actions/data-manager.js
+0
-0
index.js
src/actions/index.js
+101
-0
network-manager.js
src/actions/network-manager.js
+92
-0
No files found.
package.json
View file @
4a8a1a6c
...
@@ -43,5 +43,6 @@
...
@@ -43,5 +43,6 @@
"last 1 firefox version"
,
"last 1 firefox version"
,
"last 1 safari version"
"last 1 safari version"
]
]
}
},
"proxy"
:
"http://localhost:3001"
}
}
src/actions/data-manager.js
0 → 100644
View file @
4a8a1a6c
This diff is collapsed.
Click to expand it.
src/actions/index.js
0 → 100644
View file @
4a8a1a6c
export
const
ADD_BUILDING
=
"ADD_BUILDING"
;
export
const
CHANGE_NEW_BUILDING
=
"CHANGE_NEW_BUILDING"
export
const
CHANGE_NEW_UNIT_COUNT
=
"CHANGE_NEW_UNIT_COUNT"
export
const
CHANGE_NEW_UNIT
=
"CHANGE_NEW_UNIT"
export
const
CHANGE_OWNER
=
"CHANGE_OWNER"
export
const
CREATE_DOCUMENTS
=
"CREATE_DOCUMENTS"
;
export
const
CHANGE_SELECTED_BUILDING
=
"CHANGE_SELECTED_BUILDING"
export
const
GENERIC_STATE_CHANGE
=
"GENERIC_STATE_CHANGE"
export
const
FETCH_ALL_BUILDING_SUCCESS
=
"FETCH_ALL_BUILDING_SUCCESS"
export
const
TOKEN_RECEIVED
=
"TOKEN_RECEIVED"
export
const
TOKEN_RECEIVED_MANAGER
=
"TOKEN_RECEIVED_MANAGER"
export
const
TENANT_BUILDING_RECEIVED
=
"TENANT_BUILDING_RECEIVED"
export
const
TENANT_VOTING_RECEIVED
=
"TENANT_VOTING_RECEIVED"
export
const
UNAUTHENTICATED
=
"UNAUTHENTICATED"
//TBD:
// ChangeTenant/Owner
// SubmitIssue
// AddProposal
// Vote
export
function
genericAction
(
type
,
payload
){
return
{
type
,
payload
}
}
// export function tokenReceived(jwt, role){
// return genericAction(TOKEN_RECEIVED, {jwt, role})
// }
// export function
// export function tenantBuildingReceived(building){
// return genericAction(TENANT_BUILDING_RECEIVED, building)
// }
//TODO: this should be called when is already added
export
function
addBuilding
(
building
)
{
return
{
type
:
ADD_BUILDING
,
payload
:
building
}
}
export
function
changeNewBuilding
(
updateData
)
{
return
{
type
:
CHANGE_NEW_BUILDING
,
payload
:
updateData
}
}
export
function
changeNewUnitCount
(
count
)
{
return
{
type
:
CHANGE_NEW_UNIT_COUNT
,
payload
:
count
}
}
export
function
changeNewUnit
(
updateData
)
{
return
{
type
:
CHANGE_NEW_UNIT
,
payload
:
updateData
}
}
export
function
changeNewUnitOwner
(
updateData
)
{
return
{
type
:
CHANGE_OWNER
,
payload
:
updateData
}
}
export
const
fetchBuildingsSuccess
=
buildings
=>
({
type
:
FETCH_ALL_BUILDING_SUCCESS
,
payload
:
{
buildings
}
});
//TODO: this should not be called by reducer
export
function
createDocuments
(
building
)
{
// console.log(building)
return
{
type
:
CREATE_DOCUMENTS
,
payload
:
building
}
}
export
function
changeSelectedBuilding
(
buildingId
,
selectedIndex
)
{
return
{
type
:
CHANGE_SELECTED_BUILDING
,
payload
:
{
selectedBuilding
:
buildingId
,
selectedBuildingIndex
:
selectedIndex
-
1
}
}
}
export
function
genericStateChange
(
key
,
value
)
{
return
{
type
:
GENERIC_STATE_CHANGE
,
payload
:
{
key
,
value
}
}
}
src/actions/network-manager.js
0 → 100644
View file @
4a8a1a6c
// console.log("process.env.REACT_APP_USE_DEV")
// console.log(process.env.REACT_APP_USE_DEV)
// let API_ADDRESS
// if (process.env.REACT_APP_USE_DEV) {
// // API_ADDRESS = API_ADDRESS = "http://localhost:3001"
// } else {
// API_ADDRESS = "/api"
// }
const
API_ADDRESS
=
"/api"
export
const
JWT_TENANT
=
"jwtt"
export
const
JWT_MANAGER
=
"jwtm"
function
fetchRequestBase
(
jwt
,
api_prefix
,
address
,
callback
,
dispatch
,
method
=
"GET"
,
object
=
undefined
,
isDownload
=
false
)
{
let
requestInit
=
{
method
,
headers
:
{
// 'Accept': 'application/json',
'Content-Type'
:
'application/json'
,
'Authorization'
:
localStorage
.
getItem
(
jwt
)
}
}
if
(
!
isDownload
&&
object
)
{
requestInit
[
"body"
]
=
JSON
.
stringify
(
object
)
}
return
fetch
(
API_ADDRESS
+
api_prefix
+
address
,
requestInit
)
.
then
(
res
=>
{
//NOTE: cascade promise is used in order to get both res.body and res status in same processing phase.
let
promise
;
if
(
!
isDownload
)
{
promise
=
res
.
json
()
}
else
{
promise
=
res
.
blob
()
}
promise
.
then
(
json
=>
{
//TODO: unify error handling
//TODO: verify status
if
(
!
res
.
ok
)
{
if
(
typeof
(
json
)
===
"string"
)
{
json
=
{
errorMessage
:
json
}
}
console
.
log
(
json
)
json
.
statusText
=
res
.
statusText
json
.
status
=
res
.
status
console
.
error
(
json
)
// if (json.status === "error") {}
if
(
callback
)
{
callback
(
json
,
null
,
dispatch
)
}
return
}
if
(
!
isDownload
)
{
if
(
callback
)
{
callback
(
null
,
json
,
dispatch
)
};
}
else
{
// 1. Create blob link to download
const
url
=
window
.
URL
.
createObjectURL
(
new
Blob
([
json
]));
const
link
=
document
.
createElement
(
'a'
);
link
.
href
=
url
;
link
.
setAttribute
(
'download'
,
object
);
// 2. Append to html page
document
.
body
.
appendChild
(
link
);
// 3. Force download
link
.
click
();
// 4. Clean up and remove the link
link
.
parentNode
.
removeChild
(
link
);
if
(
callback
)
{
callback
(
null
,
json
,
dispatch
)
};
}
})
.
catch
(
error
=>
{
// dispatch(fetchProductsFailure(error))
// console.error("ERR fetch")
console
.
error
(
error
)
if
(
callback
)
{
callback
(
error
,
null
,
dispatch
)
}
});
})
.
catch
(
error
=>
{
// dispatch(fetchProductsFailure(error))
// console.error("ERR fetch")
console
.
error
(
error
)
if
(
callback
)
{
callback
(
error
,
null
,
dispatch
)
}
});
}
export
function
fetchRequestManager
(
address
,
callback
,
dispatch
,
method
=
"GET"
,
object
=
undefined
,
isDownload
=
false
)
{
return
fetchRequestBase
(
JWT_MANAGER
,
"/manager"
,
address
,
callback
,
dispatch
,
method
,
object
,
isDownload
)
}
export
function
fetchRequestTenant
(...
args
)
{
return
fetchRequestBase
(
JWT_TENANT
,
"/tenant"
,
...
args
)
}
\ No newline at end of file
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