-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(optional-policies): convert UpdateAlert and Policy model to TS
- Loading branch information
Showing
4 changed files
with
88 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
export * from 'flarum/common/models/User'; | ||
|
||
declare module 'flarum/common/models/User' { | ||
export default interface User { | ||
fofTermsPoliciesHasUpdate(): boolean; | ||
fofTermsPoliciesMustAccept(): boolean; | ||
fofTermsPoliciesState(): Record< | ||
number, | ||
{ | ||
accepted_at: string; | ||
has_update: boolean; | ||
is_accepted: boolean; | ||
must_accept: boolean; | ||
} | ||
>; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import app from 'flarum/forum/app'; | ||
import Button from 'flarum/common/components/Button'; | ||
import listItems from 'flarum/common/helpers/listItems'; | ||
import AcceptPoliciesModal from './AcceptPoliciesModal'; | ||
|
||
let temporarilyHidden = false; | ||
|
||
/** | ||
* Renders similarly to Flarum's Alert, but with an additional .container inside | ||
*/ | ||
export default class UpdateAlert { | ||
shouldShowAlert() { | ||
if (temporarilyHidden) { | ||
return false; | ||
} | ||
|
||
const user = app.session.user; | ||
|
||
return user && user.fofTermsPoliciesHasUpdate(); | ||
} | ||
|
||
view() { | ||
if (!this.shouldShowAlert() || !app.session.user) { | ||
return null; | ||
} | ||
|
||
const controls = [ | ||
<Button | ||
className="Button Button--link" | ||
onclick={() => { | ||
app.modal.show(AcceptPoliciesModal); | ||
}} | ||
> | ||
{app.translator.trans('fof-terms.forum.update-alert.review')} | ||
</Button>, | ||
]; | ||
|
||
const dismissControl = []; | ||
|
||
if (!app.session.user.fofTermsPoliciesMustAccept()) { | ||
dismissControl.push( | ||
<Button | ||
icon="fas fa-times" | ||
className="Button Button--link Button--icon Alert-dismiss" | ||
onclick={() => { | ||
temporarilyHidden = true; | ||
}} | ||
/> | ||
); | ||
} | ||
|
||
return ( | ||
<div className="Alert Alert-info"> | ||
<div className="container"> | ||
<span className="Alert-body"> | ||
{app.session.user.fofTermsPoliciesMustAccept() | ||
? app.translator.trans('fof-terms.forum.update-alert.must-accept-message') | ||
: app.translator.trans('fof-terms.forum.update-alert.can-accept-message')} | ||
</span> | ||
<ul className="Alert-controls">{listItems(controls.concat(dismissControl))}</ul> | ||
</div> | ||
</div> | ||
); | ||
} | ||
} |