Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/app/core/components/redirect-page/redirect-page.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<section
class="container flex flex-column flex-1 my-7 mx-3 p-3 align-items-center md:p-4 md:flex-row md:justify-content-between"
>
<img
class="redirect-image w-8 md:w-6"
ngSrc="assets/images/laptop-books.png"
width="500"
height="346"
[alt]="'redirectPage.altText' | translate"
/>

<div class="flex flex-column align-items-center m-4 md:align-items-start">
<h2>{{ 'redirectPage.header' | translate }}</h2>
<p class="mt-4">{{ 'redirectPage.message' | translate }}</p>

<div class="flex flex-column mt-4 gap-4 md:flex-row md:justify-content-start">
<a class="p-button font-bold no-underline" [href]="redirectDestination">
{{ 'common.buttons.continue' | translate }}
</a>
<p-button severity="info" (click)="goBack()">
{{ 'common.buttons.goBack' | translate }}
</p-button>
</div>
</div>
</section>
19 changes: 19 additions & 0 deletions src/app/core/components/redirect-page/redirect-page.component.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
@use "styles/mixins" as mix;

:host {
@include mix.flex-center;
flex: 1;
background: var(--gradient-3);
}

.container {
background: var(--white);
border-radius: 0.75rem;
box-shadow: 0 2px 4px var(--grey-outline);
color: var(--dark-blue-1);
}

.redirect-image {
height: auto;
object-fit: contain;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { CurrentResourceSelectors } from '@osf/shared/stores/current-resource/current-resource.selectors';

import { provideOSFCore } from '@testing/osf.testing.provider';
import { provideMockStore } from '@testing/providers/store-provider.mock';

import { RedirectPageComponent } from './redirect-page.component';

const mockResource = {
id: 'mock-resource-id',
type: 'mock-resource-type',
redirectUrl: 'https://example.com',
permissions: [],
redirectAutomatically: false,
};

describe('RedirectPageComponent', () => {
let component: RedirectPageComponent;
let fixture: ComponentFixture<RedirectPageComponent>;

beforeEach(() => {
TestBed.configureTestingModule({
imports: [RedirectPageComponent],
providers: [
provideOSFCore(),
provideMockStore({
selectors: [{ selector: CurrentResourceSelectors.getCurrentResource, value: mockResource }],
}),
],
});

fixture = TestBed.createComponent(RedirectPageComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});

it('should render continue link and go back button', () => {
const link = fixture.nativeElement.querySelector('a') as HTMLAnchorElement;
expect(link.getAttribute('href')).toBe(component.redirectDestination);
const button = fixture.nativeElement.querySelector('p-button') as HTMLButtonElement;
expect(button).toBeTruthy();
});

it('should call goBack when go back button is clicked', () => {
const goBackSpy = vi.spyOn(component, 'goBack');
const button = fixture.nativeElement.querySelector('p-button') as HTMLButtonElement;
button.click();
expect(goBackSpy).toHaveBeenCalled();
});
});
42 changes: 42 additions & 0 deletions src/app/core/components/redirect-page/redirect-page.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { select } from '@ngxs/store';

import { TranslatePipe } from '@ngx-translate/core';

import { Button } from 'primeng/button';

import { NgOptimizedImage } from '@angular/common';
import { Component, OnDestroy, OnInit } from '@angular/core';

import { CurrentResourceSelectors } from '@osf/shared/stores/current-resource/current-resource.selectors';

@Component({
selector: 'osf-redirect-page',
imports: [Button, NgOptimizedImage, TranslatePipe],
templateUrl: './redirect-page.component.html',
styleUrl: './redirect-page.component.scss',
})
export class RedirectPageComponent implements OnInit, OnDestroy {
private readonly currentResource = select(CurrentResourceSelectors.getCurrentResource);

readonly redirectDelay = 5000;
readonly redirectDestination = this.currentResource()?.redirectUrl ?? '';

private timer?: ReturnType<typeof setTimeout>;

ngOnInit() {
const resource = this.currentResource();
if (resource && resource.redirectUrl) {
this.timer = setTimeout(() => {
window.location.href = this.redirectDestination;
}, this.redirectDelay);
}
}

ngOnDestroy() {
clearTimeout(this.timer);
}

goBack() {
history.back();
}
}
6 changes: 6 additions & 0 deletions src/assets/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,7 @@
"editAndResubmit": "Edit And Resubmit",
"embed": "Embed",
"filter": "Filter",
"goBack": "Go back",
"hide": "Hide",
"leaveThisView": "Leave this view",
"loadMore": "Load more",
Expand Down Expand Up @@ -2166,6 +2167,11 @@
"view": "View"
}
},
"redirectPage": {
"header": "You're leaving OSF.",
"message": "You’re about to leave the OSF. The site you’re about to visit has its own terms and privacy policy. You will be automatically redirected in a moment.",
"altText": "You're leaving OSF"
},
"registries": {
"addRegistration": "Add a Registration",
"browse": "Browse Registrations",
Expand Down
Binary file added src/assets/images/laptop-books.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading