2020-12-11 18:23:13 +00:00
|
|
|
import React from 'react';
|
|
|
|
import PopupBase from '../PopupBase';
|
|
|
|
import style from './NewActorPopup.module.css';
|
2020-12-17 20:53:22 +00:00
|
|
|
import {callAPI} from '../../../utils/Api';
|
2021-01-22 21:05:21 +00:00
|
|
|
import {GeneralSuccess} from '../../../types/GeneralTypes';
|
2020-12-29 19:39:30 +00:00
|
|
|
|
|
|
|
interface NewActorPopupProps {
|
|
|
|
onHide: () => void;
|
|
|
|
}
|
2020-12-11 18:23:13 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* creates modal overlay to define a new Tag
|
|
|
|
*/
|
2020-12-29 19:39:30 +00:00
|
|
|
class NewActorPopup extends React.Component<NewActorPopupProps> {
|
|
|
|
render(): JSX.Element {
|
2020-12-11 18:23:13 +00:00
|
|
|
return (
|
|
|
|
<PopupBase title='Add new Tag' onHide={this.props.onHide} height='200px' width='400px'>
|
|
|
|
<NewActorPopupContent onHide={this.props.onHide}/>
|
|
|
|
</PopupBase>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-29 19:39:30 +00:00
|
|
|
export class NewActorPopupContent extends React.Component<NewActorPopupProps> {
|
|
|
|
value: string | undefined;
|
2020-12-11 18:23:13 +00:00
|
|
|
|
2020-12-29 19:39:30 +00:00
|
|
|
render(): JSX.Element {
|
2020-12-11 18:23:13 +00:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<div>
|
2020-12-29 19:39:30 +00:00
|
|
|
<input type='text' placeholder='Actor Name' onChange={(v): void => {
|
2020-12-11 18:23:13 +00:00
|
|
|
this.value = v.target.value;
|
|
|
|
}}/></div>
|
2020-12-29 19:39:30 +00:00
|
|
|
<button className={style.savebtn} onClick={(): void => this.storeselection()}>Save</button>
|
2020-12-11 18:23:13 +00:00
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* store the filled in form to the backend
|
|
|
|
*/
|
2020-12-29 19:39:30 +00:00
|
|
|
storeselection(): void {
|
2020-12-11 18:23:13 +00:00
|
|
|
// check if user typed in name
|
|
|
|
if (this.value === '' || this.value === undefined) return;
|
|
|
|
|
2020-12-29 19:39:30 +00:00
|
|
|
callAPI('actor.php', {action: 'createActor', actorname: this.value}, (result: GeneralSuccess) => {
|
2020-12-17 20:53:22 +00:00
|
|
|
if (result.result !== 'success') {
|
|
|
|
console.log('error occured while writing to db -- todo error handling');
|
|
|
|
console.log(result.result);
|
|
|
|
}
|
|
|
|
this.props.onHide();
|
|
|
|
});
|
2020-12-11 18:23:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default NewActorPopup;
|