Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feature/connect_map_115' into 13…
Browse files Browse the repository at this point in the history
…8-create-economic-event

# Conflicts:
#	src/HOC/pages/inventory/InventoryPage.generated.tsx
#	src/HOC/pages/inventory/InventoryPage.graphql
#	src/fe/resource/create/useCreateResource.generated.tsx
#	src/fe/resource/create/useCreateResource.graphql
#	src/ui/pages/inventory/index.tsx
#	src/ui/pages/resource/index.tsx
  • Loading branch information
BaseBlocks authored and BaseBlocks committed Oct 22, 2021
2 parents 8ccac59 + a13e78c commit f97919c
Show file tree
Hide file tree
Showing 53 changed files with 985 additions and 608 deletions.
109 changes: 109 additions & 0 deletions src/HOC/modules/CreateMenuHOK/CreateDropdown.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import * as React from 'react';
import { Dropdown } from '../../../ui/modules/Dropdown';
import { Plus, PlusSquare, Users, X } from 'react-feather';
import { Flex, Text } from 'rebass/styled-components';
import { Trans } from '@lingui/macro';
import styled from '../../../ui/themes/styled';

type TCreateDropdown = {
toggleDropdown: () => void;
createCommunity: () => void;
createIntent: () => void;
createResource: () => void;
};

export const CreateDropdown: React.FC<TCreateDropdown> = ({
toggleDropdown,
createCommunity,
createIntent,
createResource
}) => {
return (
<Dropdown orientation={'top'} close={toggleDropdown}>
<Action>
<StyledClose onClick={toggleDropdown}>
<X color="#05244F" />
</StyledClose>
</Action>
<List lined>
<Item variant="link" onClick={() => createCommunity()}>
<span>
<Users size={16} color={'#333'} />
</span>
<Text variant="text">
<Trans>New Community</Trans>
</Text>
</Item>
<Item variant="link" onClick={() => createIntent()}>
<span>
<PlusSquare size={16} color={'#333'} />
</span>
<Text variant="text">
<Trans>Create a new intent</Trans>
</Text>
</Item>
<Item variant="link" onClick={() => createResource()}>
<span>
<Plus size={16} color={'#333'} />
</span>
<Text variant="text">
<Trans>Create a new resource</Trans>
</Text>
</Item>
</List>
</Dropdown>
);
};

const List = styled.div<{ lined?: boolean }>`
padding: 8px;
`;

const Action = styled(Flex)`
justify-content: flex-end;
padding: 12px 20px;
`;
const Item = styled(Flex)`
line-height: 50px;
height: 50px;
cursor: pointer;
align-items: center;
& span {
display: inline-block;
margin-right: 8px;
.--rtl & {
margin-right: 0px;
margin-left: 8px;
}
& svg {
vertical-align: sub;
}
}
& a {
color: inherit !important;
text-decoration: none;
}
&:hover {
color: ${props => props.theme.colors.primary};
}
`;

export const StyledClose = styled.button`
width: 18px;
height: 18px;
position: relative;
background: transparent;
border: none;
cursor: pointer;
padding: 0;
z-index: 10;
margin: 0;
&:focus {
outline: none;
}
`;
75 changes: 75 additions & 0 deletions src/HOC/modules/CreateMenuHOK/CreateMenuHOK.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import React, { useReducer } from 'react';
import { CreateDropdown } from './CreateDropdown';
import Modal from '../../../ui/modules/Modal';
import { CreateCommunityPanelHOC } from '../CreateCommunityPanel/createCommunityPanelHOC';
import { CreateIntentPanelHOC } from '../CreateIntentPanel/createIntentPanelHOC';
import { CreateLocationPanelHOC } from '../CreateLocationPanel/CreateLocationPanelHOK';
import { CreateResourcePanelHOC } from '../CreateResourcePanel/CreateResourcePanelHOC';
import { useNotifyMustLogin } from '../../lib/notifyMustLogin';

export type Props = {
open: boolean;
openHandler: (open: boolean) => void;
};

export const CreateMenuHOK: React.FC<Props> = ({ open, openHandler }: Props) => {
const notifiedMustLogin = useNotifyMustLogin();
const [showCreateLocation, toggleShowCreateLocation] = React.useState(false);
const [showCreateCommunity, toggleShowCreateCommunity] = useReducer(
is => (notifiedMustLogin() ? false : !is),
false
);

const [showCreateIntent, toggleShowCreateIntent] = useReducer(
is => (notifiedMustLogin() ? false : !is),
false
);

const [showCreateResource, toggleShowCreateResource] = useReducer(
is => (notifiedMustLogin() ? false : !is),
false
);

const CreateCommunityModal = showCreateCommunity ? (
<Modal closeModal={toggleShowCreateCommunity}>
<CreateCommunityPanelHOC done={toggleShowCreateCommunity} />
</Modal>
) : null;

const CreateIntentModal = showCreateIntent ? (
<Modal closeModal={toggleShowCreateIntent}>
<CreateIntentPanelHOC done={toggleShowCreateIntent} />
</Modal>
) : null;

const CreateResourceModal = showCreateResource ? (
<Modal closeModal={toggleShowCreateResource}>
{showCreateLocation ? (
<CreateLocationPanelHOC done={toggleShowCreateLocation} />
) : (
<CreateResourcePanelHOC
done={toggleShowCreateResource}
toggleCreateLocation={toggleShowCreateLocation}
/>
)}
</Modal>
) : null;

return (
<>
{CreateCommunityModal}
{CreateIntentModal}
{CreateResourceModal}
{open && (
<CreateDropdown
createCommunity={toggleShowCreateCommunity}
createResource={toggleShowCreateIntent}
createIntent={toggleShowCreateResource}
toggleDropdown={() => {
openHandler(!open);
}}
/>
)}
</>
);
};
11 changes: 5 additions & 6 deletions src/HOC/modules/CreateResourcePanel/CreateResourcePanelHOC.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ export const CreateResourcePanelHOC: FC<Props> = ({

const formik = useFormik<any>({
initialValues: {
name: '',
note: '',
image: undefined,
name: resource?.name || '',
note: resource?.note || '',
image: resource?.image || '',
atLocation: {
id: '',
id: resource?.currentLocation?.id || '',
label: ''
},
action: {
Expand Down Expand Up @@ -116,8 +116,7 @@ export const CreateResourcePanelHOC: FC<Props> = ({
})
.then((response: any) => {
if (!response.errors) {
const newId =
response?.data?.createEconomicEvent.economicEvent.resourceInventoriedAs.id;
const newId = response?.data?.createEconomicEvent?.economicResource?.id;
const redirect = `/resource/${newId} `;
done();
history.replace(redirect);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ import { useCreateDefaultResource } from '../../../fe/resourceDefault/useCreateD
import { useAgentsQuery } from '../../../fe/resourceDefault/useCreateResource.generated';
import { useActionsQuery } from '../IntentPanel/Actions.generated';
import { EconomicEventManagerProps } from '../../../ui/modules/EconomicEventManager';
import {
useUnitsPagesQuery,
} from './EconomicEventManager.generated';
import { useUnitsPagesQuery } from './EconomicEventManager.generated';

export const EconomicEventManagerHOC: FC = ({ children }) => {
const [providerList, setProviderList] = React.useState<
Expand All @@ -17,7 +15,6 @@ export const EconomicEventManagerHOC: FC = ({ children }) => {
const [receiverList, setReceiverList] = React.useState<
null | undefined | [] | { id: string; name: string }[]
>([]);
const [action, setAction] = React.useState('');

const intentActionsQ = useActionsQuery();
const { data } = useAgentsQuery();
Expand Down Expand Up @@ -72,7 +69,7 @@ export const EconomicEventManagerHOC: FC = ({ children }) => {
providerList: providerList,
receiverList: receiverList,
unitPages,
setAction
setAction: () => {}
};

const childrenWithProps = React.Children.map(children, child => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,22 @@ export const CreateEconomicEventOnResourcePanelHOC: FC<Props> = ({ done, resourc
formik,
done
};

const handlerCloseSecondTab = () => {
toggleTab(0);
done();
};
const [showCreateLocation, toggleShowCreateLocation] = useState(false);
const CreateResourceModal = (
<>
{showCreateLocation ? (
<CreateLocationPanelHOC done={toggleShowCreateLocation} />
) : (
<CreateResourcePanelHOC done={done} toggleCreateLocation={toggleShowCreateLocation} />
<CreateResourcePanelHOC
done={handlerCloseSecondTab}
toggleCreateLocation={toggleShowCreateLocation}
resource={formik.values}
/>
)}
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,13 @@ export const UpdateEconomicResourceHOC: FC<Props> = ({ done, resource, ...props
initialValues: React.useMemo(() => {
let values = {
note: '',
image: '' || undefined,
location: ''
image: '' || undefined
};
if (resource) {
values = {
//@ts-ignore
name: resource.name || '',
note: resource.note || '',
image: resource.image || undefined,
atLocation: resource.currentLocation
? {
id: resource.currentLocation.id,
value: resource.currentLocation.id,
label: resource.currentLocation.name
}
: { id: '', label: '', value: '' }
image: resource.image || undefined
};
}
return values;
Expand All @@ -69,9 +60,7 @@ export const UpdateEconomicResourceHOC: FC<Props> = ({ done, resource, ...props
onSubmit: (values: UpdateResourceVariables) => {
return update({
id: resource.id,
name: values.name,
note: values.note,
atLocation: values.atLocation?.id,
image: values.image
})
.then((response: any) => {
Expand Down
Loading

0 comments on commit f97919c

Please sign in to comment.