@@ -1,77 +1,78 @@
|
||||
import { Button, Card, Col, Input, Table, Typography } from "antd";
|
||||
import React, { useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import {Button, Card, Col, Input, Table, Typography} from "antd";
|
||||
import React, {useState} from "react";
|
||||
import {useTranslation} from "react-i18next";
|
||||
|
||||
export default function ProfileShopsComponent({
|
||||
loading,
|
||||
data,
|
||||
updateActiveShop,
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
const [search, setSearch] = useState("");
|
||||
const columns = [
|
||||
{
|
||||
title: t("associations.fields.shopname"),
|
||||
dataIndex: "shopname",
|
||||
key: "shopname",
|
||||
width: "25%",
|
||||
render: (text, record) => <span>{record.bodyshop.shopname}</span>,
|
||||
},
|
||||
{
|
||||
title: t("associations.fields.active"),
|
||||
dataIndex: "active",
|
||||
key: "active",
|
||||
width: "25%",
|
||||
render: (text, record) => <span>{record.active ? "Yes" : "No"}</span>,
|
||||
},
|
||||
{
|
||||
title: t("associations.labels.actions"),
|
||||
dataIndex: "actions",
|
||||
key: "actions",
|
||||
width: "25%",
|
||||
render: (text, record) => (
|
||||
<span>
|
||||
loading,
|
||||
data,
|
||||
updateActiveShop,
|
||||
}) {
|
||||
const {t} = useTranslation();
|
||||
const [search, setSearch] = useState("");
|
||||
const columns = [
|
||||
{
|
||||
title: t("associations.fields.shopname"),
|
||||
dataIndex: "shopname",
|
||||
key: "shopname",
|
||||
width: "25%",
|
||||
render: (text, record) => <span>{record.bodyshop.shopname}</span>,
|
||||
},
|
||||
{
|
||||
title: t("associations.fields.active"),
|
||||
dataIndex: "active",
|
||||
key: "active",
|
||||
width: "25%",
|
||||
render: (text, record) => <span>{record.active ? "Yes" : "No"}</span>,
|
||||
},
|
||||
{
|
||||
title: t("associations.labels.actions"),
|
||||
dataIndex: "actions",
|
||||
key: "actions",
|
||||
width: "25%",
|
||||
render: (text, record) => (
|
||||
<span>
|
||||
{record.active ? null : (
|
||||
<Button onClick={() => updateActiveShop(record.id)}>
|
||||
Activate
|
||||
</Button>
|
||||
<Button onClick={() => updateActiveShop(record.id)}>
|
||||
Activate
|
||||
</Button>
|
||||
)}
|
||||
</span>
|
||||
),
|
||||
},
|
||||
];
|
||||
),
|
||||
},
|
||||
];
|
||||
|
||||
const filteredData =
|
||||
search === ""
|
||||
? data
|
||||
: data.filter((d) =>
|
||||
d.bodyshop.shopname.toLowerCase().includes(search.toLowerCase())
|
||||
);
|
||||
const filteredData =
|
||||
search === ""
|
||||
? data
|
||||
: data.filter((d) =>
|
||||
d.bodyshop.shopname.toLowerCase().includes(search.toLowerCase())
|
||||
);
|
||||
|
||||
return (
|
||||
<Col span={24}>
|
||||
<Card
|
||||
title={
|
||||
<Typography.Title level={4}>
|
||||
{t("profile.labels.activeshop")}
|
||||
</Typography.Title>
|
||||
}
|
||||
extra={
|
||||
<Input.Search
|
||||
value={search}
|
||||
onChange={(e) => setSearch(e.target.value)}
|
||||
allowClear
|
||||
placeholder={t("general.labels.search")}
|
||||
/>
|
||||
}
|
||||
>
|
||||
<Table
|
||||
pagination={false}
|
||||
loading={loading}
|
||||
columns={columns}
|
||||
rowKey="id"
|
||||
dataSource={filteredData}
|
||||
/>
|
||||
</Card>
|
||||
</Col>
|
||||
);
|
||||
return (
|
||||
<Col span={24}>
|
||||
<Card
|
||||
title={
|
||||
<Typography.Title level={4}>
|
||||
{t("profile.labels.activeshop")}
|
||||
</Typography.Title>
|
||||
}
|
||||
extra={
|
||||
<Input.Search
|
||||
value={search}
|
||||
onChange={(e) => setSearch(e.target.value)}
|
||||
allowClear
|
||||
placeholder={t("general.labels.search")}
|
||||
/>
|
||||
}
|
||||
>
|
||||
<Table
|
||||
pagination={false}
|
||||
loading={loading}
|
||||
columns={columns}
|
||||
rowKey="id"
|
||||
dataSource={filteredData}
|
||||
/>
|
||||
</Card>
|
||||
</Col>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,77 +1,71 @@
|
||||
import { useMutation, useQuery } from "@apollo/client";
|
||||
import {useMutation, useQuery} from "@apollo/client";
|
||||
import React from "react";
|
||||
import { logImEXEvent } from "../../firebase/firebase.utils";
|
||||
import {
|
||||
QUERY_ALL_ASSOCIATIONS,
|
||||
UPDATE_ACTIVE_ASSOCIATION,
|
||||
} from "../../graphql/associations.queries";
|
||||
import {logImEXEvent, messaging} from "../../firebase/firebase.utils";
|
||||
import {QUERY_ALL_ASSOCIATIONS, UPDATE_ACTIVE_ASSOCIATION,} from "../../graphql/associations.queries";
|
||||
import AlertComponent from "../alert/alert.component";
|
||||
import ProfileShopsComponent from "./profile-shops.component";
|
||||
import axios from "axios";
|
||||
import { messaging } from "../../firebase/firebase.utils";
|
||||
import { getToken } from "firebase/messaging";
|
||||
import {getToken} from "firebase/messaging";
|
||||
|
||||
import {connect} from "react-redux";
|
||||
import {createStructuredSelector} from "reselect";
|
||||
import {selectBodyshop, selectCurrentUser,} from "../../redux/user/user.selectors";
|
||||
|
||||
import { connect } from "react-redux";
|
||||
import { createStructuredSelector } from "reselect";
|
||||
import {
|
||||
selectBodyshop,
|
||||
selectCurrentUser,
|
||||
} from "../../redux/user/user.selectors";
|
||||
const mapStateToProps = createStructuredSelector({
|
||||
bodyshop: selectBodyshop,
|
||||
currentUser: selectCurrentUser,
|
||||
bodyshop: selectBodyshop,
|
||||
currentUser: selectCurrentUser,
|
||||
});
|
||||
const mapDispatchToProps = (dispatch) => ({
|
||||
//setUserLanguage: language => dispatch(setUserLanguage(language))
|
||||
//setUserLanguage: language => dispatch(setUserLanguage(language))
|
||||
});
|
||||
export default connect(
|
||||
mapStateToProps,
|
||||
mapDispatchToProps
|
||||
mapStateToProps,
|
||||
mapDispatchToProps
|
||||
)(ProfileShopsContainer);
|
||||
|
||||
export function ProfileShopsContainer({ bodyshop, currentUser }) {
|
||||
const { loading, error, data } = useQuery(QUERY_ALL_ASSOCIATIONS, {
|
||||
fetchPolicy: "network-only",
|
||||
nextFetchPolicy: "network-only",
|
||||
variables: {
|
||||
email: currentUser.email,
|
||||
},
|
||||
skip: !currentUser,
|
||||
});
|
||||
const [updateActiveAssociation] = useMutation(UPDATE_ACTIVE_ASSOCIATION);
|
||||
|
||||
const updateActiveShop = async (newActiveAssocId) => {
|
||||
logImEXEvent("profile_change_active_shop");
|
||||
|
||||
try {
|
||||
const fcm_tokens = await getToken(messaging);
|
||||
|
||||
await axios.post("/notifications/unsubscribe", {
|
||||
fcm_tokens,
|
||||
imexshopid: bodyshop.imexshopid,
|
||||
type: "messaging",
|
||||
});
|
||||
} catch (error) {
|
||||
console.log("No FCM token. Skipping unsubscribe.");
|
||||
}
|
||||
|
||||
await updateActiveAssociation({
|
||||
variables: {
|
||||
newActiveAssocId: newActiveAssocId,
|
||||
},
|
||||
export function ProfileShopsContainer({bodyshop, currentUser}) {
|
||||
const {loading, error, data} = useQuery(QUERY_ALL_ASSOCIATIONS, {
|
||||
fetchPolicy: "network-only",
|
||||
nextFetchPolicy: "network-only",
|
||||
variables: {
|
||||
email: currentUser.email,
|
||||
},
|
||||
skip: !currentUser,
|
||||
});
|
||||
const [updateActiveAssociation] = useMutation(UPDATE_ACTIVE_ASSOCIATION);
|
||||
|
||||
//Force window refresh.
|
||||
const updateActiveShop = async (newActiveAssocId) => {
|
||||
logImEXEvent("profile_change_active_shop");
|
||||
|
||||
window.location.reload();
|
||||
};
|
||||
try {
|
||||
const fcm_tokens = await getToken(messaging);
|
||||
|
||||
if (error) return <AlertComponent type="error" message={error.message} />;
|
||||
return (
|
||||
<ProfileShopsComponent
|
||||
loading={loading}
|
||||
data={data ? data.associations : null}
|
||||
updateActiveShop={updateActiveShop}
|
||||
/>
|
||||
);
|
||||
await axios.post("/notifications/unsubscribe", {
|
||||
fcm_tokens,
|
||||
imexshopid: bodyshop.imexshopid,
|
||||
type: "messaging",
|
||||
});
|
||||
} catch (error) {
|
||||
console.log("No FCM token. Skipping unsubscribe.");
|
||||
}
|
||||
|
||||
await updateActiveAssociation({
|
||||
variables: {
|
||||
newActiveAssocId: newActiveAssocId,
|
||||
},
|
||||
});
|
||||
|
||||
//Force window refresh.
|
||||
|
||||
window.location.reload();
|
||||
};
|
||||
|
||||
if (error) return <AlertComponent type="error" message={error.message}/>;
|
||||
return (
|
||||
<ProfileShopsComponent
|
||||
loading={loading}
|
||||
data={data ? data.associations : null}
|
||||
updateActiveShop={updateActiveShop}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user