Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

📅 Add last updated to resource detail page #474

Merged
merged 3 commits into from
Jun 23, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for changing all this back 😂

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 && (
<t style={{ color: 'gray' }}>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is a t tag? is there a reason we can't do span/div?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bruh idk I swear it was used for text but that might've been a completely different project lol

{`\n\n${intl.formatMessage(
detailMessages.lastUpdated,
)} ${intl.formatDate(lastUpdated, {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for doing the format date!

year: 'numeric',
month: 'long',
day: 'numeric',
})}`}
</t>
)}
</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 && (
<t style={{ color: 'gray' }}>
{`\n\n${intl.formatMessage(
detailMessages.lastUpdated,
)} ${intl.formatDate(lastUpdated, {
year: 'numeric',
month: 'long',
day: 'numeric',
})}`}
</t>
)}
</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