Skip to content

Commit

Permalink
Update Collection
Browse files Browse the repository at this point in the history
  • Loading branch information
koechkevin committed Oct 10, 2023
1 parent 2c8f4cf commit 725fc2e
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 34 deletions.
12 changes: 6 additions & 6 deletions apps/codeforafrica/src/components/AddressCard/AddressCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,18 @@ const AddressCard = React.forwardRef(function AddressCard(props, ref) {
active,
addressLine1,
addressLine2,
zipcode,
zipCode,
city,
country,
onClick,
title,
} = props;
const handleClick = (e) => {
if (onClick) {
onClick(e, title);
onClick(e, city);
}
};

if (!title) {
if (!city) {
return null;
}
const ownerState = { active };
Expand All @@ -44,7 +43,7 @@ const AddressCard = React.forwardRef(function AddressCard(props, ref) {
<CardActionArea onClick={handleClick}>
<CardContent sx={{ p: 0 }}>
<RichTypography sx={{ color: "inherit" }} variant="body3Underline">
{title}
{city}
</RichTypography>
<RichTypography
// In address, we treat <p> as a line i.e.no margins.
Expand All @@ -64,7 +63,8 @@ const AddressCard = React.forwardRef(function AddressCard(props, ref) {
variant="body3"
component="span"
>
{zipcode},
{zipCode}
{zipCode ? "," : null}
</RichTypography>
<RichTypography
component="span"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@ const OfficeAddresses = React.forwardRef(function OfficeAddresses(props, ref) {
const [activeAddress, setActiveAddress] = React.useState(
addresses?.[0] ?? null,
);
const handleClickAddress = (_, addressTitle) => {
setActiveAddress(
addresses.find((address) => address.title === addressTitle),
);
const handleClickAddress = (_, city) => {
setActiveAddress(addresses.find((address) => address.city === city));
};

if (!addresses?.length) {
Expand All @@ -50,7 +48,7 @@ const OfficeAddresses = React.forwardRef(function OfficeAddresses(props, ref) {
zIndex: -1,
}}
>
<GoogleMap {...map} {...activeAddress} style={mapStyle} />
<GoogleMap {...map} {...activeAddress?.map} style={mapStyle} />
</Box>
<Section
sx={{
Expand Down Expand Up @@ -89,11 +87,11 @@ const OfficeAddresses = React.forwardRef(function OfficeAddresses(props, ref) {
sm={5}
md={2}
sx={{ order: { xs: 2, md: 0 } }}
key={address.title}
key={address.city}
>
<AddressCard
{...address}
active={address.title === activeAddress.title}
active={address.city === activeAddress.city}
onClick={handleClickAddress}
/>
</Grid>
Expand Down
26 changes: 15 additions & 11 deletions apps/codeforafrica/src/lib/data/blockify/ourOffices.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
function ourOffices(block) {
const { offices } = block;
const addresses = offices?.map((item) => ({
...item,
position: {
lng: item?.location?.[0],
lat: item?.location?.[1],
},
center: {
lng: item?.location?.[0],
lat: item?.location?.[1],
},
}));
const addresses =
offices?.map((item) => {
let location = null;
if (item?.location?.length) {
location = {
lng: item?.location?.[0],
lat: item?.location?.[1],
};
}
return {
...item,
position: location,
center: location,
};
}) ?? null;
return {
...block,
slug: block.blockType,
Expand Down
2 changes: 1 addition & 1 deletion apps/codeforafrica/src/payload/blocks/OurOffices.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ const OurOffices = {
required: true,
},
{
hasMany: true,
type: "relationship",
relationTo: "offices",
hasMany: true,
name: "offices",
required: true,
},
Expand Down
14 changes: 5 additions & 9 deletions apps/codeforafrica/src/payload/collections/Offices.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
const Offices = {
slug: "offices",
admin: {
group: "Settings",
defaultColumns: ["title"],
useAsTitle: "title",
group: "Organisation",
defaultColumns: ["city", "country"],
useAsTitle: "city",
},
fields: [
{
name: "title",
name: "city",
type: "text",
required: true,
},
Expand All @@ -26,11 +26,7 @@ const Offices = {
type: "text",
},
{
name: "zipcode",
type: "text",
},
{
name: "city",
name: "zipCode",
type: "text",
},
{
Expand Down

0 comments on commit 725fc2e

Please sign in to comment.