-
-
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.
fix(optional-policies): resolve null property warnings and improve UX (…
…#61) * fix(optional-policies): resolve `Attempt to read property "is_accepted" on null` warnings * Apply fixes from StyleCI * fix(optional-policies): calm down some PHPStan errors * Apply fixes from StyleCI * fix(optional-policies): make user settings label translatable * feat(optional-policies): place optional policies settings above `flarum/gdpr` * style(optional-policies): remove unnecessary space * refactor(optional-policies): convert UpdateAlert and Policy model to TS * a11y(optional-policies): add aria label to close button * refactor(optional-policies): convert AcceptPoliciesModal to JSX * feat(optional-policies): add a separate alert message for optional policy updates --------- Co-authored-by: rafaucau <[email protected]>
- Loading branch information
Showing
9 changed files
with
192 additions
and
181 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
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 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,75 @@ | ||
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; | ||
|
||
return user && user.fofTermsPoliciesHasUpdate(); | ||
} | ||
|
||
hasOnlyOptionalUpdates() { | ||
const { user } = app.session; | ||
return user && !user.fofTermsPoliciesMustAccept() && user.fofTermsPoliciesHasUpdate(); | ||
} | ||
|
||
view() { | ||
const { user } = app.session; | ||
|
||
if (!this.shouldShowAlert() || !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 (!user.fofTermsPoliciesMustAccept()) { | ||
dismissControl.push( | ||
<Button | ||
icon="fas fa-times" | ||
className="Button Button--link Button--icon Alert-dismiss" | ||
onclick={() => { | ||
temporarilyHidden = true; | ||
}} | ||
aria-label={app.translator.trans('fof-terms.forum.update-alert.close')} | ||
/> | ||
); | ||
} | ||
|
||
return ( | ||
<div className="Alert Alert-info"> | ||
<div className="container"> | ||
<span className="Alert-body"> | ||
{this.hasOnlyOptionalUpdates() | ||
? app.translator.trans('fof-terms.forum.update-alert.can-accept-optional-message') | ||
: 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> | ||
); | ||
} | ||
} |
Oops, something went wrong.