{"size": 5914, "ext": "js", "max_stars_repo_path": "src/pages/AddServicePage.js", "max_stars_repo_name": "callumgare/ask-izzy", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pages/AddServicePage.js", "max_issues_repo_name": "callumgare/ask-izzy", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/pages/AddServicePage.js", "max_forks_repo_name": "callumgare/ask-izzy", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 31.7956989247, "max_line_length": 79, "alphanum_fraction": 0.4556983429}
/* @flow */

import url from "url";
import React from "react";

import components from "../components";
import routerContext from "../contexts/router-context";

type Props = {}

type State = {
    isFormDone: boolean,
}

class AddServicePage extends React.Component<Props, State> {
    issUrl: any; // Flowtype core declares url.parse(): any
    handleMessage: Function;

    constructor(props: Object): void {
        super(props);

        this.state = {
            isFormDone: false,
        };

        this.handleMessage = this.handleMessage.bind(this);
        this.issUrl = "";

        if (typeof window !== "undefined" && window.ISS_URL) {
            let {auth, ...urlObj} = url.parse(window.ISS_URL);
            this.issUrl = urlObj;
        }
    }

    static contextType = routerContext;

    componentDidMount(): void {
        if (typeof window !== "undefined") {
            window.addEventListener("message", this.handleMessage, false);
        }

    }

    componentWillUnmount(): void {
        if (typeof window !== "undefined") {
            window.removeEventListener("message", this.handleMessage);
        }
    }

    handleMessage(event: MessageEvent): void {
        const origin = event.origin

        if (origin !== `${this.issUrl.protocol}//${this.issUrl.hostname}`) {
            return;
        }

        switch (typeof event === "object" && event.data) {
        case "formSubmitted":
            this.setState({
                isFormDone: true,
            });
            break;

        case "formLoaded":
            window.scrollTop(0, 0);
            break;

        default:
            break;
        }
    }

    render() {
        const body = this.state.isFormDone ? this.renderSuccessMessage()
            : this.renderForm();

        return (
            <div className="AddServicePage">
                <components.AppBar
                    title="Add a service"
                    onBackTouchTap={this.context.router.history.goBack}
                />

                <div className="body">
                    {body}
                </div>
            </div>
        );
    }

    renderSuccessMessage() {
        return (
            <div>
                <p>Thank you. The information you provided may be adjusted for
                consistency in presentation and will be available online
                within seven (7) calendar days from submission.</p>
            </div>
        );
    }

    renderForm() {
        const issUrl = url.format(this.issUrl);

        return (
            <div>
                <p>
                    The service listings on Ask Izzy come
                    from <a href="https://www.infoxchange.org">
                    Infoxchange</a>&apos;s Service Seeker database,
                    Australia&apos;s largest up-to-date directory of
                    health and welfare services.
                </p>
                <p>
                    We would love your help keeping the service listings
                    as current as possible.
                </p>
                <p>
                    <strong>
                        If you notice that service information is incorrect:
                    </strong>
                </p>
                <p>
                    We know that service and program information changes all
                    the time. If you think that a listing needs updating or
                    you see an error, please&nbsp;
                    <a
                        href={
                            "mailto:support@askizzy.org.au" +
                                "?subject=" +
                                encodeURIComponent(
                                    `Your Ask Izzy feedback`) +
                                "&body=" +
                                encodeURIComponent(
                                    `Service name:

                                    Contact name:

                                    Contact number:

                                    Contact email:

                                    Details of change:

                                    `.replace(/^ +/gm, "")
                                )
                        }
                    >
                        email to let us know
                    </a>.
                </p>
                <p>
                    <strong>
                        If you want to add a new service:
                    </strong>
                </p>
                <p>
                    If your service doesn&apos;t appear when you search for
                    it on Ask Izzy, we&apos;d love you to submit a new service
                    listing using the form below. Your entry will then be
                    checked by our database team before it gets added.
                </p>
                <p>
                    We know the form is quite long! Unfortunately it needs
                    to be – we gather as much information as possible so we
                    can put people in touch with the right services for their
                    needs. Note that not all the fields need to be filled in
                    and we will follow up with you if we need any additional
                    information.
                </p>
                <p>
                    If your service is complex (e.g. the same service is
                    offered at multiple sites or there are complex
                    eligibility criteria) or if you&apos;re having trouble with
                    the form, <a href="mailto:database@infoxchange.org">email
                    us</a> some basic information about the service and
                    we&apos;ll contact you to find out more.
                </p>

                <iframe src={`${issUrl}/add-service-form?form=ask-izzy`} />
            </div>
        );
    }
}

export default AddServicePage;
