Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ workflows:
only:
- main
- dev
- rollback

jobs:
build_docker_image:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"dev": "next dev -p 8080",
"build": "next build",
"start": "next start",
"lint": "next lint"
Expand Down
4 changes: 3 additions & 1 deletion src/components/cepResult/cepResult.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ interface propsCepResult {
estado: string;
latitude: number;
longitude: number;
tipoLogradouro: string;
}

export const CepResult: FunctionComponent<propsCepResult> = ({
Expand All @@ -26,6 +27,7 @@ export const CepResult: FunctionComponent<propsCepResult> = ({
estado,
latitude,
longitude,
tipoLogradouro,
}) => {
return (
<>
Expand All @@ -35,7 +37,7 @@ export const CepResult: FunctionComponent<propsCepResult> = ({
<strong>CEP:</strong> {cep}
</p>
<p>
<strong>Logradouro:</strong> {logradouro}
<strong>Logradouro:</strong> {`${tipoLogradouro} ${logradouro}`}
</p>
<p>
<strong>Bairro:</strong> {bairro}
Expand Down
29 changes: 25 additions & 4 deletions src/pages/cep/[...cep].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,17 @@ export const getServerSideProps: GetServerSideProps = async (context: any) => {
};
}

const response = await fetch(`${process.env.API_LINK}/cep/${cep}`);
const credentials = `${process.env.CLIENT_ID}:${process.env.CLIENT_SECRET}`;
const base64Credentials = btoa(credentials);

const response = await fetch(`${process.env.API_LINK}/cep/${cep}`, {
headers: {
Authorization: `Basic ${base64Credentials}`,
},
next: {
revalidate: 2592000,
},
});
const post = await response.json();

return {
Expand All @@ -38,9 +48,19 @@ const CepPage: FunctionComponent<CepPageProps> = ({ post, cep }) => {
const pageTitle = post.cep
? `Informações do CEP ${post.cep}`
: "CEP não encontrado";
const pageDescription = post.cep
? `Detalhes do CEP ${post.cep}: ${post.logradouro}, ${post.bairro}, ${post.cidade}, ${post.estado}.`
: "A busca pelo CEP não retornou resultados.";
const pageDescriptionParts = [
post.cep && `Detalhes do CEP ${post.cep}`,
post.logradouro && `${post.tipoLogradouro} ${post.logradouro}`,
post.bairro?.nome && post.bairro.nome,
post.cidade?.nome && post.cidade.nome,
post.estado?.nome && post.estado?.nome,
post.estado?.uf && post.estado?.uf,
].filter(Boolean);

const pageDescription =
pageDescriptionParts.length > 0
? pageDescriptionParts.join(", ")
: "A busca pelo CEP não retornou resultados.";

mixpanel.track("Cep Search", {
cep: post?.cep,
Expand Down Expand Up @@ -87,6 +107,7 @@ const CepPage: FunctionComponent<CepPageProps> = ({ post, cep }) => {
estado={`${post.estado?.nome} - ${post.estado?.uf}`}
latitude={post.latitude}
longitude={post.longitude}
tipoLogradouro={post.tipoLogradouro}
/>
)}
</div>
Expand Down