Skip to content

Commit

Permalink
📅 Add last updated to resource detail page (#474)
Browse files Browse the repository at this point in the history
* this was a lot more work than I expected

* comment

* div

Co-authored-by: Feeshay <[email protected]>
  • Loading branch information
Feeshay and Feeshay authored Jun 23, 2021
1 parent f1f5063 commit b94c9a8
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 74 deletions.
83 changes: 49 additions & 34 deletions client/src/components/desktop/ResourceDetail.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ function ResourceDetail(props) {
const [addressString, setAddresString] = useState('');
const [financialAidDetails, setFinancialAidDetails] = useState(null);
const [contacts, setContacts] = useState(null);
const [lastUpdated, setLastUpdated] = useState('');

const updateIsSaved = useCallback(
(savedSet) => {
Expand All @@ -84,48 +85,51 @@ function ResourceDetail(props) {
async function didMount() {
const response = await getResourceByID(match.params.id, true);
if (response !== null) {
const { res } = response;
setName(res.name);
setPhone(res.phoneNumbers);
setAddress(res.address ?? '');
setAddressLine2(res.addressLine2 ?? '');
setAptUnitSuite(res.aptUnitSuite ?? '');
setCity(res.city ?? '');
setState(res.state ?? '');
setZip(res.zip ?? '');
setDescription(res.description);
setLanguages(res.availableLanguages);
setCategory(res.category[0]);
setSubcategory(res.subcategory[0]);
setCost(res.cost);
const { result } = response;
setName(result.name);
setPhone(result.phoneNumbers);
setAddress(result.address ?? '');
setAddressLine2(result.addressLine2 ?? '');
setAptUnitSuite(result.aptUnitSuite ?? '');
setCity(result.city ?? '');
setState(result.state ?? '');
setZip(result.zip ?? '');
setDescription(result.description);
setLanguages(result.availableLanguages);
setCategory(result.category[0]);
setSubcategory(result.subcategory[0]);
setCost(result.cost);
setLat(
res?.geoLocation === null ||
res?.geoLocation === undefined ||
res?.geoLocation?.coordinates === null ||
res?.geoLocation?.coordinates === undefined ||
Number.isNaN(res?.geoLocation?.coordinates[1])
result?.geoLocation === null ||
result?.geoLocation === undefined ||
result?.geoLocation?.coordinates === null ||
result?.geoLocation?.coordinates === undefined ||
Number.isNaN(result?.geoLocation?.coordinates[1])
? 0.0
: res?.geoLocation?.coordinates[1],
: result?.geoLocation?.coordinates[1],
);
setLng(
res?.geoLocation === null ||
res?.geoLocation === undefined ||
res?.geoLocation?.coordinates === null ||
res?.geoLocation?.coordinates === undefined ||
Number.isNaN(res?.geoLocation?.coordinates[0])
result?.geoLocation === null ||
result?.geoLocation === undefined ||
result?.geoLocation?.coordinates === null ||
result?.geoLocation?.coordinates === undefined ||
Number.isNaN(result?.geoLocation?.coordinates[0])
? 0.0
: res?.geoLocation?.coordinates[0],
: result?.geoLocation?.coordinates[0],
);
setEmail(res.email ?? '');
setWebsite(res.website ?? '');
setEligibility(res.eligibilityRequirements);
setInternalNotes(res.internalNotes);
setEmail(result.email ?? '');
setWebsite(result.website ?? '');
setEligibility(result.eligibilityRequirements);
setInternalNotes(result.internalNotes);
setHours(
res.hoursOfOperation ? res.hoursOfOperation.hoursOfOperation : [],
result.hoursOfOperation
? result.hoursOfOperation.hoursOfOperation
: [],
);
setRequiredDocuments(res.requiredDocuments);
setFinancialAidDetails(res.financialAidDetails);
setContacts(res.contacts);
setRequiredDocuments(result.requiredDocuments);
setFinancialAidDetails(result.financialAidDetails);
setContacts(result.contacts);
setLastUpdated(result.lastUpdated ?? '');

if (authed) {
let savedSet = new Set();
Expand Down Expand Up @@ -390,6 +394,17 @@ function ResourceDetail(props) {
id: `resource-eligibilityRequirements-${match.params.id}`,
defaultMessage: eligibility,
})}`}
{lastUpdated && (
<div style={{ color: 'gray' }}>
{`\n\n${intl.formatMessage(
detailMessages.lastUpdated,
)} ${intl.formatDate(lastUpdated, {
year: 'numeric',
month: 'long',
day: 'numeric',
})}`}
</div>
)}
</Col>
</Row>
<Row>
Expand Down
92 changes: 52 additions & 40 deletions client/src/components/mobile/ResourceDetailMobile.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,12 @@ const ResourceDetailMobile = (props: Props) => {
const [phone, setPhone] = useState([]);
const [address, setAddress] = useState(null);
const [addressLine2, setAddressLine2] = useState(null);
// const [aptUnitSuite, setAptUnitSuite] = useState('');
const [city, setCity] = useState('');
const [state, setState] = useState('');
const [zip, setZip] = useState('');
const [languages, setLanguages] = useState([]);
const [requiredDocuments, setRequiredDocuments] = useState(null);
const [cost, setCost] = useState(null);
// const [internalNotes, setInternalNotes] = useState([]);
const [hours, setHours] = useState(null);
const [image, setImage] = useState(null);
const [financialAidDetails, setFinancialAidDetails] = useState(null);
Expand All @@ -79,7 +77,7 @@ const ResourceDetailMobile = (props: Props) => {
const [lng, setLng] = useState(0);
const [distFromResource, setDistFromResource] = useState(null);
const [eligibility, setEligibility] = useState('');
// const [modalVisible, setModalVisible] = useState(false);
const [lastUpdated, setLastUpdated] = useState('');
const [isSaved, setIsSaved] = useState(false);
const [isWithinOperationHours, setIsWithinOperationHours] = useState(null);

Expand All @@ -89,61 +87,62 @@ const ResourceDetailMobile = (props: Props) => {
const response = await getResourceByID(resourceId, true);

if (response) {
const { res } = response;
const { result } = response;

setImage(
res.image && res.image !== ''
? res.image
: determineStockPhoto(res.category, res.subcategory),
result.image && result.image !== ''
? result.image
: determineStockPhoto(result.category, result.subcategory),
);

setCategory(res.category[0]);
setSubcategory(res.subcategory[0]);
setCategory(result.category[0]);
setSubcategory(result.subcategory[0]);

setName(res.name);
setDescription(res.description);
setName(result.name);
setDescription(result.description);

setPhone(res.phoneNumbers);
setEmail(res.email);
setWebsite(res.website);
setPhone(result.phoneNumbers);
setEmail(result.email);
setWebsite(result.website);

setLanguages(res.availableLanguages);
setCost(res.cost);
setLanguages(result.availableLanguages);
setCost(result.cost);

setAddress(res.address);
setAddressLine2(res.addressLine2);
setCity(res.city);
setState(res.state);
setZip(res.zip);
setRequiredDocuments(res.requiredDocuments);
setEligibility(res.eligibilityRequirements);
setFinancialAidDetails(res.financialAidDetails);
setContacts(res.contacts);
setAddress(result.address);
setAddressLine2(result.addressLine2);
setCity(result.city);
setState(result.state);
setZip(result.zip);
setRequiredDocuments(result.requiredDocuments);
setEligibility(result.eligibilityRequirements);
setFinancialAidDetails(result.financialAidDetails);
setContacts(result.contacts);
setLastUpdated(result.lastUpdated ?? '');

setHours(
res.hoursOfOperation &&
res.hoursOfOperation.hoursOfOperation.length > 0
? res.hoursOfOperation.hoursOfOperation
result.hoursOfOperation &&
result.hoursOfOperation.hoursOfOperation.length > 0
? result.hoursOfOperation.hoursOfOperation
: null,
);

setLat(
res?.geoLocation === null ||
res?.geoLocation === undefined ||
res?.geoLocation?.coordinates === null ||
res?.geoLocation?.coordinates === undefined ||
Number.isNaN(res?.geoLocation?.coordinates[1])
result?.geoLocation === null ||
result?.geoLocation === undefined ||
result?.geoLocation?.coordinates === null ||
result?.geoLocation?.coordinates === undefined ||
Number.isNaN(result?.geoLocation?.coordinates[1])
? 0.0
: res?.geoLocation?.coordinates[1],
: result?.geoLocation?.coordinates[1],
);
setLng(
res?.geoLocation === null ||
res?.geoLocation === undefined ||
res?.geoLocation?.coordinates === null ||
res?.geoLocation?.coordinates === undefined ||
Number.isNaN(res?.geoLocation?.coordinates[0])
result?.geoLocation === null ||
result?.geoLocation === undefined ||
result?.geoLocation?.coordinates === null ||
result?.geoLocation?.coordinates === undefined ||
Number.isNaN(result?.geoLocation?.coordinates[0])
? 0.0
: res?.geoLocation?.coordinates[0],
: result?.geoLocation?.coordinates[0],
);
} else {
setResourceExists(false);
Expand Down Expand Up @@ -359,6 +358,19 @@ const ResourceDetailMobile = (props: Props) => {
defaultMessage: eligibility,
})}`}
</Row>
<Row>
{lastUpdated && (
<div style={{ color: 'gray' }}>
{`\n\n${intl.formatMessage(
detailMessages.lastUpdated,
)} ${intl.formatDate(lastUpdated, {
year: 'numeric',
month: 'long',
day: 'numeric',
})}`}
</div>
)}
</Row>
</Col>
</Row>
</div>
Expand Down
4 changes: 4 additions & 0 deletions client/src/utils/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ export const detailMessages = defineMessages({
id: 'detailEligibility',
defaultMessage: 'Eligibility Requirements',
},
lastUpdated: {
id: 'lastUpdated',
defaultMessage: 'Last updated',
},
basicInfo: {
id: 'detailBasicInfo',
defaultMessage: 'Basic Information',
Expand Down

0 comments on commit b94c9a8

Please sign in to comment.