Skip to content

Commit

Permalink
type on function props
Browse files Browse the repository at this point in the history
  • Loading branch information
fridaklockmann committed Jul 31, 2019
1 parent f8dfd40 commit 00f1b16
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 51 deletions.
6 changes: 2 additions & 4 deletions packages/admin-frontend/pages/_app.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,8 @@ class App extends NextApp {
pageProps = await Component.getInitialProps(ctx);
}

const userHasAuthToken = hasAuthToken(ctx.req); //true

const userHasAdminPrivileges = hasClaim(claims.readAdmin, ctx.req); //true
console.log(hasAuthToken(ctx.req), hasClaim(claims.readAdmin, ctx.req));
const userHasAuthToken = hasAuthToken(ctx.req);
const userHasAdminPrivileges = hasClaim(claims.readAdmin, ctx.req);

// If we have response object, set a proper HTTP status code
if (!userHasAdminPrivileges && ctx.res) {
Expand Down
16 changes: 3 additions & 13 deletions packages/admin-frontend/pages/admin/featured.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,25 +71,15 @@ export default class EditFeaturedContent extends React.Component<Props, State> {

getFeaturedContent = async (languageCode: string) => {
const featuredContentRes = await fetchFeaturedContent(languageCode);
const featContList = [];
let i = 0;
while (featuredContentRes.isOk) {
if (featuredContentRes.data[i]) {
featContList.push(featuredContentRes.data[i]);
} else {
break;
}
i++;
}

if (featuredContentRes.isOk) {
if (featContList[0].language.code !== languageCode) {
if (featuredContentRes.isOk && featuredContentRes.data[0]) {
if (featuredContentRes.data[0].language.code !== languageCode) {
this.setState({
featuredContentList: []
});
} else {
this.setState({
featuredContentList: featContList
featuredContentList: featuredContentRes.data
});
}
}
Expand Down
13 changes: 7 additions & 6 deletions packages/admin-frontend/pages/admin/featuredAdd.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ import { Add } from '@material-ui/icons';
import FeaturedEdit from './featuredEdit';
/** @jsx jsx */
import { css, jsx } from '@emotion/core';
import type { FeaturedContent } from '../../types';

export default function FeatureAdd(
defaultReturned: boolean,
handleSaveButtonClick: any,
handleFileChosen: any,
handleOnCancel: any,
file: any,
handleOnUpload: any,
featuredContentList: Array<any>,
handleSaveButtonClick: (boolean, FeaturedContent) => void,
handleFileChosen: (SyntheticInputEvent<EventTarget>) => void,
handleOnCancel: () => void,
file: ?File,
handleOnUpload: (string, (string, any) => void) => void,
featuredContentList: Array<FeaturedContent>,
selectedLanguage: string
) {
return (
Expand Down
58 changes: 30 additions & 28 deletions packages/admin-frontend/pages/admin/featuredEdit.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ import type { FeaturedContent } from '../../types';
type Props = {
i: number,
button: any,
featuredContentList: Array<any>,
featuredContentList: Array<FeaturedContent>,
selectedLanguage: string,
defaultReturned: boolean,
handleSaveButtonClick: any,
handleFileChosen: any,
handleOnCancel: any,
file: any,
handleOnUpload: any
handleSaveButtonClick: (boolean, FeaturedContent) => void,
handleFileChosen: (SyntheticInputEvent<EventTarget>) => void,
handleOnCancel: () => void,
file: ?File,
handleOnUpload: (string, (string, any) => void) => void
};
type State = {
open: boolean
Expand Down Expand Up @@ -55,11 +55,11 @@ export default class FeaturedEdit extends React.Component<Props, State> {
};
}

handleClickOpen() {
handleClickOpen = () => {
this.setState({
open: true
});
}
};
handleClose() {
this.setState({
open: false
Expand All @@ -73,9 +73,17 @@ export default class FeaturedEdit extends React.Component<Props, State> {
this.setState({ open: false });
};
render() {
const {
button,
featuredContentList,
selectedLanguage,
i,
defaultReturned,
file
} = this.props;
return (
<>
<div onClick={this.handleClickOpen.bind(this)}>{this.props.button}</div>
<div onClick={this.handleClickOpen}>{button}</div>

<Dialog
open={this.state.open}
Expand All @@ -85,12 +93,8 @@ export default class FeaturedEdit extends React.Component<Props, State> {
<div style={{ padding: 25 }}>
<>
<Form
initialValues={
this.props.featuredContentList[this.props.i] || {}
}
onSubmit={this.handleSaveButtonClick(
this.props.defaultReturned
)}
initialValues={featuredContentList[i] || {}}
onSubmit={this.handleSaveButtonClick(defaultReturned)}
validate={handleValidate}
render={({ handleSubmit, pristine, invalid, form }) => (
<form>
Expand All @@ -101,7 +105,7 @@ export default class FeaturedEdit extends React.Component<Props, State> {
fullWidth
error={meta.error && meta.touched}
margin="normal"
disabled={this.props.selectedLanguage === ''}
disabled={selectedLanguage === ''}
label="Title"
{...input}
/>
Expand All @@ -114,7 +118,7 @@ export default class FeaturedEdit extends React.Component<Props, State> {
fullWidth
margin="normal"
error={meta.error && meta.touched}
disabled={this.props.selectedLanguage === ''}
disabled={selectedLanguage === ''}
label="Description"
{...input}
multiline
Expand All @@ -130,7 +134,7 @@ export default class FeaturedEdit extends React.Component<Props, State> {
type="url"
error={meta.error && meta.touched}
margin="normal"
disabled={this.props.selectedLanguage === ''}
disabled={selectedLanguage === ''}
label="Link"
{...input}
/>
Expand All @@ -155,7 +159,7 @@ export default class FeaturedEdit extends React.Component<Props, State> {
margin="normal"
error={meta.error && meta.touched}
type="url"
disabled={this.props.selectedLanguage === ''}
disabled={selectedLanguage === ''}
label="Image Url"
{...input}
/>
Expand All @@ -172,18 +176,18 @@ export default class FeaturedEdit extends React.Component<Props, State> {
<span>or</span>

<input
disabled={this.props.selectedLanguage === ''}
disabled={selectedLanguage === ''}
type="file"
accept="image/*"
value=""
onChange={event => this.props.handleFileChosen(event)}
/>

{this.props.file && (
{file && (
<UploadFileDialog
language={this.props.selectedLanguage}
selectedFile={this.props.file}
objectURL={URL.createObjectURL(this.props.file)}
language={selectedLanguage}
selectedFile={file}
objectURL={URL.createObjectURL(file)}
onCancel={this.props.handleOnCancel}
onUpload={url =>
this.props.handleOnUpload(url, form.change)
Expand All @@ -208,16 +212,14 @@ export default class FeaturedEdit extends React.Component<Props, State> {
type="submit"
onClick={handleSubmit}
>
{this.props.featuredContentList.length > this.props.i
? 'Save changes'
: 'Save'}
{featuredContentList.length > i ? 'Save changes' : 'Save'}
</Button>
<Button
color="secondary"
disabled={pristine}
onClick={form.reset}
>
{this.props.featuredContentList.length > this.props.i
{featuredContentList.length > i
? 'Discard changes'
: 'Discard'}
</Button>
Expand Down

0 comments on commit 00f1b16

Please sign in to comment.